Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

[#1427] Add support for getting HTTP status message from HttpResponse #457

Closed
wants to merge 1 commit into from

3 participants

Matthias van der Vlies Nicolas Leroux Morten Kjetland
Matthias van der Vlies

It makes sense to be able to retrieve not only the status code, but also the status message. Perhaps it also makes sense to rename WS.HttpResponse.getStatus() to WS.HttpResponse.getStatusCode()? I did not do this for this commit as I wanted to keep the API backwards compatible.

Signed-off-by: Matthias van der Vlies matthias@lancelot-telecom.nl

Matthias van der Vlies [#1427] Add support for getting HTTP status message from HttpResponse
Signed-off-by: Matthias van der Vlies <matthias@lancelot-telecom.nl>
ee54af9
Nicolas Leroux
Collaborator

What is the use case? I mean if you get the code you get the message and vice versa no?

Matthias van der Vlies

I'm writing against an external API which returns multiple reasons per response code. Also according to the RFC http://www.w3.org/Protocols/rfc2616/rfc2616-sec6.html#sec6.1.1

"The individual values of the numeric status codes defined for HTTP/1.1, and an example set of corresponding Reason-Phrase's, are presented below. The reason phrases listed here are only recommendations -- they MAY be replaced by local equivalents without affecting the protocol."

Imho this itself gives enough reason to be able to extract it, and almost any client out there supports it.

Nicolas Leroux
Collaborator

Ok makes sense

Morten Kjetland
Collaborator

thanks.

merged into 1.2.x and master

Morten Kjetland mbknor closed this March 12, 2012
Matthias van der Vlies

Thanks for the merge. Any chance the request for 2.0 (playframework/playframework#129) will get merged in too?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 1 unique commit by 1 author.

Feb 14, 2012
Matthias van der Vlies [#1427] Add support for getting HTTP status message from HttpResponse
Signed-off-by: Matthias van der Vlies <matthias@lancelot-telecom.nl>
ee54af9
This page is out of date. Refresh to see the latest.
6  framework/src/play/libs/WS.java
@@ -539,6 +539,12 @@ public FileParam(File file, String name) {
539 539
         public abstract Integer getStatus();
540 540
 
541 541
         /**
  542
+         * The HTTP status text
  543
+         * @return the status text of the http response
  544
+         */
  545
+        public abstract String getStatusText();
  546
+
  547
+        /**
542 548
          * @return true if the status code is 20x, false otherwise
543 549
          */
544 550
         public boolean success() {
9  framework/src/play/libs/ws/WSAsync.java
@@ -555,6 +555,15 @@ public Integer getStatus() {
555 555
             return this.response.getStatusCode();
556 556
         }
557 557
 
  558
+        /**
  559
+         * the HTTP status text
  560
+         * @return the status text of the http response
  561
+         */
  562
+        @Override
  563
+        public String getStatusText() {
  564
+            return this.response.getStatusText();
  565
+        }
  566
+
558 567
         @Override
559 568
         public String getHeader(String key) {
560 569
             return response.getHeader(key);
11  framework/src/play/libs/ws/WSUrlFetch.java
@@ -266,6 +266,7 @@ private void checkFileBody(HttpURLConnection connection) throws IOException {
266 266
 
267 267
         private String body;
268 268
         private Integer status;
  269
+        private String statusText;
269 270
         private Map<String, List<String>> headersMap;
270 271
 
271 272
         /**
@@ -275,6 +276,7 @@ private void checkFileBody(HttpURLConnection connection) throws IOException {
275 276
         public HttpUrlfetchResponse(HttpURLConnection connection) {
276 277
             try {
277 278
                 this.status = connection.getResponseCode();
  279
+                this.statusText = connection.getResponseMessage();
278 280
                 this.headersMap = connection.getHeaderFields();
279 281
                 InputStream is = null;
280 282
                 if (this.status >= HttpURLConnection.HTTP_BAD_REQUEST) {
@@ -300,6 +302,15 @@ public Integer getStatus() {
300 302
             return status;
301 303
         }
302 304
 
  305
+        /**
  306
+         * the HTTP status text
  307
+         * @return the status text of the http response
  308
+         */
  309
+        @Override
  310
+        public String getStatusText() {
  311
+            return statusText;
  312
+        }
  313
+
303 314
         @Override
304 315
         public String getHeader(String key) {
305 316
             return headersMap.containsKey(key) ? headersMap.get(key).get(0) : null;
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.