A DESCRIPTION OF THE REQUEST :
Request not to disconnect inputstream when receiving 401.
sun.net.www.protocol.http.HttpURLConnection#getInputStream() closes the connection if receiving a 401 in streaming mode, resulting getErrorStream() returning null. Source code: http://grepcode.com/file/repository.grepcode.com/java/root/jdk/openjdk/8-b132/sun/net/www/protocol/http/HttpURLConnection.java#1633
if (respCode == HTTP_UNAUTHORIZED) {
if (streaming()) {
disconnectInternal();
throw new HttpRetryException (
RETRY_MSG2, HTTP_UNAUTHORIZED);
}
JUSTIFICATION :
There are web servers that return meaningful error messages when declines an authentication request and we would like to parse the response body when receiving 401.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
try {
InputStream content = conn.getInputStream();
// ...
} catch (IOException ioe) {
InputStream content = conn.getErrorStream();
// content should not be null.
}
ACTUAL -
try {
InputStream content = conn.getInputStream();
// ...
} catch (IOException ioe) {
InputStream content = conn.getErrorStream();
// content is null when getting a 401
}
CUSTOMER SUBMITTED WORKAROUND :
There is no workaround right now because the error stream only gets set when calling getInputStream(), which always closes the connection when getting a 401 in streaming mode.
Request not to disconnect inputstream when receiving 401.
sun.net.www.protocol.http.HttpURLConnection#getInputStream() closes the connection if receiving a 401 in streaming mode, resulting getErrorStream() returning null. Source code: http://grepcode.com/file/repository.grepcode.com/java/root/jdk/openjdk/8-b132/sun/net/www/protocol/http/HttpURLConnection.java#1633
if (respCode == HTTP_UNAUTHORIZED) {
if (streaming()) {
disconnectInternal();
throw new HttpRetryException (
RETRY_MSG2, HTTP_UNAUTHORIZED);
}
JUSTIFICATION :
There are web servers that return meaningful error messages when declines an authentication request and we would like to parse the response body when receiving 401.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
try {
InputStream content = conn.getInputStream();
// ...
} catch (IOException ioe) {
InputStream content = conn.getErrorStream();
// content should not be null.
}
ACTUAL -
try {
InputStream content = conn.getInputStream();
// ...
} catch (IOException ioe) {
InputStream content = conn.getErrorStream();
// content is null when getting a 401
}
CUSTOMER SUBMITTED WORKAROUND :
There is no workaround right now because the error stream only gets set when calling getInputStream(), which always closes the connection when getting a 401 in streaming mode.