@@ -52,22 +52,24 @@ public class Response implements ProxyObject {
52
52
53
53
private static final Logger logger = LoggerFactory .getLogger (Response .class );
54
54
55
- public static final Response OK = new Response (200 );
55
+ public static final Response OK = new Response (200 , "OK" );
56
56
57
57
private static final String BODY = "body" ;
58
58
private static final String BODY_BYTES = "bodyBytes" ;
59
59
private static final String STATUS = "status" ;
60
+ private static final String STATUS_TEXT = "statusText" ;
60
61
private static final String HEADER = "header" ;
61
62
private static final String HEADERS = "headers" ;
62
63
private static final String HEADER_VALUES = "headerValues" ;
63
64
private static final String DATA_TYPE = "dataType" ;
64
65
private static final String RESPONSE_TIME = "responseTime" ;
65
66
66
- private static final String [] KEYS = new String []{STATUS , HEADER , HEADERS , HEADER_VALUES , BODY , DATA_TYPE , BODY_BYTES , RESPONSE_TIME };
67
+ private static final String [] KEYS = new String []{STATUS , STATUS_TEXT , HEADER , HEADERS , HEADER_VALUES , BODY , DATA_TYPE , BODY_BYTES , RESPONSE_TIME };
67
68
private static final Set <String > KEY_SET = new HashSet (Arrays .asList (KEYS ));
68
69
private static final JsArray KEY_ARRAY = new JsArray (KEYS );
69
70
70
71
private int status ;
72
+ private String statusText ;
71
73
private Map <String , List <String >> headers ;
72
74
private Object body ;
73
75
@@ -76,15 +78,21 @@ public class Response implements ProxyObject {
76
78
private long responseTime ;
77
79
78
80
public Response (int status ) {
81
+ this (status , null );
82
+ }
83
+
84
+ public Response (int status , String statusText ) {
79
85
this .status = status ;
86
+ this .statusText = statusText ;
80
87
}
81
88
82
- public Response (int status , Map <String , List <String >> headers , byte [] body ) {
83
- this (status , headers , body , null );
89
+ public Response (int status , String statusText , Map <String , List <String >> headers , byte [] body ) {
90
+ this (status , statusText , headers , body , null );
84
91
}
85
92
86
- public Response (int status , Map <String , List <String >> headers , byte [] body , ResourceType resourceType ) {
93
+ public Response (int status ,String statusText , Map <String , List <String >> headers , byte [] body , ResourceType resourceType ) {
87
94
this .status = status ;
95
+ this .statusText = statusText ;
88
96
this .headers = headers ;
89
97
this .body = body ;
90
98
this .resourceType = resourceType ;
@@ -98,6 +106,14 @@ public void setStatus(int status) {
98
106
this .status = status ;
99
107
}
100
108
109
+ public String getStatusText () {
110
+ return statusText ;
111
+ }
112
+
113
+ public void setStatusText (String statusText ) {
114
+ this .statusText = statusText ;
115
+ }
116
+
101
117
public int getDelay () {
102
118
return delay ;
103
119
}
@@ -253,6 +269,8 @@ public Object getMember(String key) {
253
269
switch (key ) {
254
270
case STATUS :
255
271
return status ;
272
+ case STATUS_TEXT :
273
+ return statusText ;
256
274
case HEADER :
257
275
return HEADER_FUNCTION ;
258
276
case HEADERS :
@@ -284,6 +302,7 @@ public Object getMember(String key) {
284
302
public Map <String , Object > toMap () {
285
303
Map <String , Object > map = new HashMap ();
286
304
map .put (STATUS , status );
305
+ map .put (STATUS_TEXT , statusText );
287
306
map .put (HEADERS , JsonUtils .simplify (headers ));
288
307
map .put (BODY , getBodyConverted ());
289
308
map .put (RESPONSE_TIME , responseTime );
@@ -309,6 +328,9 @@ public void putMember(String key, Value value) {
309
328
case STATUS :
310
329
status = value .asInt ();
311
330
break ;
331
+ case STATUS_TEXT :
332
+ statusText = value .asString ();
333
+ break ;
312
334
case HEADERS :
313
335
setHeaders ((Map ) JsValue .toJava (value ));
314
336
break ;
@@ -321,6 +343,9 @@ public void putMember(String key, Value value) {
321
343
public String toString () {
322
344
StringBuilder sb = new StringBuilder ();
323
345
sb .append ("[status: " ).append (status );
346
+ if (statusText != null ) {
347
+ sb .append (", text: " ).append (statusText );
348
+ }
324
349
sb .append (", responseTime: " ).append (responseTime );
325
350
if (resourceType != null && resourceType != ResourceType .BINARY ) {
326
351
sb .append (", type: " ).append (resourceType );
0 commit comments