On Tue, 12 Sep 2023 12:05:51 GMT, Daniel Fuchs <[email protected]> wrote:

> Hi Vyom, the HttpClient is a different API. We're talking about the 
> HttpURLConnection here. You're calling `HttpURLConnection::getOutputStream()` 
> ; it blocks for a while waiting for 100 from the server. If the server 
> returns 100, or takes too long to return 100, the method call returns an 
> OutputStream that you can use to write the request body. If the server 
> returns anything but 100, the method call throws a `ProtocolException`, as 
> there is no point sending a body at this point. Therefore no OutputStream 
> will be returned. You should catch the exception and look at the status code: 
> then you can decide how to proceed depending on whether the status code 
> returned is 200, 417, or something else. This may not be ideal but this is 
> how it is supposed to work in HttpURLConnection. If we had a different API we 
> could have returned an `Optional<OutputStream>` but that's not how the API 
> was designed. `Optional` didn't exists at the time.

If this is the case then  the my proposed fix is correct. I will update the PR 
to address minor review comments.

-------------

PR Comment: https://git.openjdk.org/jdk/pull/15483#issuecomment-1717286586

Reply via email to