@@ -46,9 +46,8 @@ public final class Response implements Closeable {
4646 private Response (int status , String reason , Map <String , Collection <String >> headers , Body body ) {
4747 checkState (status >= 200 , "Invalid status code: %s" , status );
4848 this .status = status ;
49- this .reason = checkNotNull (reason , "reason" );
50- LinkedHashMap <String , Collection <String >>
51- copyOf =
49+ this .reason = reason ; //nullable
50+ LinkedHashMap <String , Collection <String >> copyOf =
5251 new LinkedHashMap <String , Collection <String >>();
5352 copyOf .putAll (checkNotNull (headers , "headers" ));
5453 this .headers = Collections .unmodifiableMap (copyOf );
@@ -84,6 +83,11 @@ public int status() {
8483 return status ;
8584 }
8685
86+ /**
87+ * Nullable and not set when using http/2
88+ *
89+ * See https://github.com/http2/http2-spec/issues/202
90+ */
8791 public String reason () {
8892 return reason ;
8993 }
@@ -101,16 +105,15 @@ public Body body() {
101105
102106 @ Override
103107 public String toString () {
104- StringBuilder builder = new StringBuilder ();
105- builder .append ("HTTP/1.1 " ).append (status ).append (' ' ).append (reason ).append ('\n' );
108+ StringBuilder builder = new StringBuilder ("HTTP/1.1 " ).append (status );
109+ if (reason != null ) builder .append (' ' ).append (reason );
110+ builder .append ('\n' );
106111 for (String field : headers .keySet ()) {
107112 for (String value : valuesOrEmpty (headers , field )) {
108113 builder .append (field ).append (": " ).append (value ).append ('\n' );
109114 }
110115 }
111- if (body != null ) {
112- builder .append ('\n' ).append (body );
113- }
116+ if (body != null ) builder .append ('\n' ).append (body );
114117 return builder .toString ();
115118 }
116119
0 commit comments