Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions framework/src/play/libs/WS.java
Expand Up @@ -538,6 +538,12 @@ public static abstract class HttpResponse {
*/
public abstract Integer getStatus();

/**
* The HTTP status text
* @return the status text of the http response
*/
public abstract String getStatusText();

/**
* @return true if the status code is 20x, false otherwise
*/
Expand Down
9 changes: 9 additions & 0 deletions framework/src/play/libs/ws/WSAsync.java
Expand Up @@ -555,6 +555,15 @@ public Integer getStatus() {
return this.response.getStatusCode();
}

/**
* the HTTP status text
* @return the status text of the http response
*/
@Override
public String getStatusText() {
return this.response.getStatusText();
}

@Override
public String getHeader(String key) {
return response.getHeader(key);
Expand Down
11 changes: 11 additions & 0 deletions framework/src/play/libs/ws/WSUrlFetch.java
Expand Up @@ -266,6 +266,7 @@ public static class HttpUrlfetchResponse extends HttpResponse {

private String body;
private Integer status;
private String statusText;
private Map<String, List<String>> headersMap;

/**
Expand All @@ -275,6 +276,7 @@ public static class HttpUrlfetchResponse extends HttpResponse {
public HttpUrlfetchResponse(HttpURLConnection connection) {
try {
this.status = connection.getResponseCode();
this.statusText = connection.getResponseMessage();
this.headersMap = connection.getHeaderFields();
InputStream is = null;
if (this.status >= HttpURLConnection.HTTP_BAD_REQUEST) {
Expand All @@ -300,6 +302,15 @@ public Integer getStatus() {
return status;
}

/**
* the HTTP status text
* @return the status text of the http response
*/
@Override
public String getStatusText() {
return statusText;
}

@Override
public String getHeader(String key) {
return headersMap.containsKey(key) ? headersMap.get(key).get(0) : null;
Expand Down