@@ -67,9 +67,6 @@ public final class HttpOpener extends DefaultObjectPipe<String, ObjectReceiver<R
67
67
private static final Pattern HEADER_FIELD_SEPARATOR_PATTERN = Pattern .compile (HEADER_FIELD_SEPARATOR );
68
68
private static final Pattern HEADER_VALUE_SEPARATOR_PATTERN = Pattern .compile (HEADER_VALUE_SEPARATOR );
69
69
70
- private static final int SUCCESS_CODE_MIN = 200 ;
71
- private static final int SUCCESS_CODE_MAX = 399 ;
72
-
73
70
private final Map <String , String > headers = new HashMap <>();
74
71
75
72
private Method method ;
@@ -260,11 +257,9 @@ public void process(final String input) {
260
257
connection .getOutputStream ().write (requestBody .getBytes ());
261
258
}
262
259
263
- final InputStream errorStream = connection .getErrorStream ();
264
- final InputStream inputStream = errorStream != null ?
265
- getErrorStream (errorStream ) : getInputStream (connection );
266
-
260
+ final InputStream inputStream = getInputStream (connection );
267
261
final String contentEncoding = getEncoding (connection .getContentEncoding ());
262
+
268
263
getReceiver ().process (new InputStreamReader (inputStream , contentEncoding ));
269
264
}
270
265
catch (final IOException e ) {
@@ -294,30 +289,19 @@ private InputStream getInputStream(final HttpURLConnection connection) throws IO
294
289
return connection .getInputStream ();
295
290
}
296
291
catch (final IOException e ) {
297
- final int responseCode = connection .getResponseCode ();
298
- if (responseCode >= SUCCESS_CODE_MIN && responseCode <= SUCCESS_CODE_MAX ) {
299
- throw e ;
292
+ final InputStream errorStream = connection .getErrorStream ();
293
+ if (errorStream != null ) {
294
+ return getErrorStream ( errorStream ) ;
300
295
}
301
296
else {
302
- final StringBuilder sb = new StringBuilder (String .valueOf (responseCode ));
303
-
304
- final String responseMessage = connection .getResponseMessage ();
305
- if (responseMessage != null ) {
306
- sb .append (" - " ).append (responseMessage );
307
- }
308
-
309
- return getErrorStream (getInputStream (sb .toString ()));
297
+ throw e ;
310
298
}
311
299
}
312
300
}
313
301
314
- private InputStream getInputStream (final String string ) {
315
- return new ByteArrayInputStream (string .getBytes ());
316
- }
317
-
318
302
private InputStream getErrorStream (final InputStream errorStream ) {
319
303
if (errorPrefix != null ) {
320
- final InputStream errorPrefixStream = getInputStream (errorPrefix );
304
+ final InputStream errorPrefixStream = new ByteArrayInputStream (errorPrefix . getBytes () );
321
305
return new SequenceInputStream (errorPrefixStream , errorStream );
322
306
}
323
307
else {
0 commit comments