Example usage for com.google.gwt.xhr.client XMLHttpRequest getAllResponseHeaders

List of usage examples for com.google.gwt.xhr.client XMLHttpRequest getAllResponseHeaders

Introduction

In this page you can find the example usage for com.google.gwt.xhr.client XMLHttpRequest getAllResponseHeaders.

Prototype

public abstract String getAllResponseHeaders();

Source Link

Document

Gets all the HTTP response headers, as a single string.

Usage

From source file:com.gwtpro.html5.fileapi.client.upload.UploadRequest.java

License:Apache License

private static Header[] getHeaders(XMLHttpRequest xmlHttp) {
    String allHeaders = xmlHttp.getAllResponseHeaders();
    String[] unparsedHeaders = allHeaders.split("\n");
    Header[] parsedHeaders = new Header[unparsedHeaders.length];
    for (int i = 0, n = unparsedHeaders.length; i < n; ++i) {
        String unparsedHeader = unparsedHeaders[i];
        if (unparsedHeader.length() == 0) {
            continue;
        }// w w  w.java2s  .co m
        int endOfNameIdx = unparsedHeader.indexOf(':');
        if (endOfNameIdx < 0) {
            continue;
        }
        final String name = unparsedHeader.substring(0, endOfNameIdx).trim();
        final String value = unparsedHeader.substring(endOfNameIdx + 1).trim();
        Header header = new Header() {

            @Override
            public String getName() {
                return name;
            }

            @Override
            public String getValue() {
                return value;
            }

            @Override
            public String toString() {
                return name + " : " + value;
            }
        };
        parsedHeaders[i] = header;
    }
    return parsedHeaders;
}

From source file:playn.http.HttpHtml.java

License:Apache License

private List<String> getAllResponseHeaderNames(XMLHttpRequest xhr) {
    List<String> headers = new ArrayList<String>();
    String all = xhr.getAllResponseHeaders();
    for (String line : all.split("\n")) { // Can't use BufferedReader because of GWT
        try {//w  ww.j  a va  2 s .co m
            String[] tokens = line.split(":");
            // ignore the actual header value, just add the header name
            if (tokens.length > 0)
                headers.add(tokens[0]);
        } catch (Exception e) {
            PlayN.log().warn("Error while processing a response header", e);
            // ignore this and continue reading other response headers
        }
    }
    return headers;
}