Stefan
Stefan

Reputation: 14863

200 instead of 304 in Response

Simple problem:

onResponseReceive getStatusCode returns 200 instead of 304. Fiddler tells me that the Response statuscode is 304.

What do I do: I constantly poll the server for new data (every 10 seconds). If the data hasn't changed, it responses with 304, else with 200 and the whole data. In the onResponseReceived method, the statuscode is always 200, and the data is always present.

Any tipps how to get the 304. I read something about If-Modified-Since, which would causes a whole resend of the data (with code 200) but I actually want the 304. I also don't want to comapre the data by hand, to see if it changed.

GWT Code:

RequestBuilder requestBuilder = new RequestBuilder(RequestBuilder.GET,
                dataUrl);

        requestBuilder.setHeader("_____", "none");
        requestBuilder.setHeader("_______", "_________");
        requestBuilder.setCallback(new RequestCallback() {

            @Override
            public void onResponseReceived(Request request, Response response) {
                PrintResponse.printResponse(response, "EntryPoints");
            if (response.getStatusCode() == 200) {.....}  

            }

            @Override
            public void onError(Request request, Throwable exception) {

            }
        });

        try {
            requestBuilder.send();
        } catch (RequestException e) {
            e.printStackTrace();
        }

Response:

HTTP/1.1 304
Content-Type: application/json
Cache-Control: max-age=0
Content-Length: 0
Date: Thu, 19 Apr 2012 10:49:10 GMT
Server: ________
Connection: Keep-Alive
Keep-Alive: timeout=60

Best Regards, Stefan

Upvotes: 2

Views: 1309

Answers (1)

oligofren
oligofren

Reputation: 22923

This is actually a bug in Chrome, not GWT. You do get HTTP 304, as Fiddler says, but Chrome displays it as HTTP 200 for some reason. I have seen it for years.

To verify this, try opening the Network tab in Chrome Dev Tools, identify the network request and right-click to "Copy as curl (bash)". Then paste the command into a terminal, append -v (for header info) and run it. You will then see you get a HTTP 304. You have now done exactly what Chrome did, including all request headers.

Upvotes: 0

Related Questions