Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    If-Modified-Since HTTP header broken for DataSources in Chrome

    We're using a data source to poll XML data into a grid from a rest service that uses the "If-Modified-Since" HTTP request header to identify whether the XML data has changed. This looks to be broken versus Chrome.

    Given the following request made via DataSource:
    Code:
    	public void refreshOnlyRecentTests() {
    		final Timer timer = new Timer() {
    			public void run() {
    				refreshOnlyRecentTests();
    			}
    		};
    		
    		DataSource dataSource = new DataSource("rest/test/instances/by-status/finished/0/33");
    		dataSource.setRecordXPath("//DartTestInstance");
    		DSRequest requestParams = new DSRequest();
    		HashMap<String, String> httpHeaders = new HashMap<String, String>();
    		httpHeaders.put("If-Modified-Since", "Tue, 01 Feb 2013 02:03:04 GMT");
    		requestParams.setHttpHeaders(httpHeaders);
    		dataSource.fetchData(null, new DSCallback() { public void execute(DSResponse response, Object rawData, DSRequest request) {
    			// Schedule this whole action again 
    			timer.schedule(5 * 1000);
    		}}, requestParams);
    	}
    I see the following request header in Chrome:
    Code:
    If-Modified-Since: Thu, 01 Jan 1970 00:00:00 GMT, Tue, 01 Feb 2013 02:03:04 GMT
    ...and the following request header in Firefox:
    Code:
    If-Modified-Since: Tue, 01 Feb 2013 02:03:04 GMT
    Interestingly, if I drop the "dataSource.setRecordXPath()" call, I see this header in Chrome and Firefox:
    Code:
    If-Modified-Since: Thu, 01 Jan 1970 00:00:00 GMT
    I tried using a plain old request builder, and it seems to work great in Firefox and Chrome:
    Code:
    	public void refreshOnlyRecentTests() {
    		final Timer timer = new Timer() {
    			public void run() {
    				refreshOnlyRecentTests();
    			}
    		};
    
    		RequestBuilder request = new RequestBuilder(RequestBuilder.GET,  "http://localhost:8080/dart/rest/test/instances/by-status/finished/0/66");
    		request.setHeader("If-Modified-Since", "Tue, 01 Feb 2013 02:03:04 GMT");
    		try {
    			request.setCallback(new RequestCallback() { 
    				public void onError(Request request, Throwable e) {} 
    				public void onResponseReceived(Request request, Response response) {
    					timer.schedule(5 * 1000);
    				}});
    			request.send();
    		} catch (RequestException e) {
    			SC.warn("REQUEST ERROR: "+e.getClass().getName()+": "+e.getMessage());
    		}
    	}
    Here is the request header from both Firefox and Chrome:
    Code:
    If-Modified-Since: Tue, 01 Feb 2013 02:03:04 GMT
    Here are the versions I'm using. I'd quote you the output from the debug console, but I'm just worn out from trying to get it to function.
    Code:
    Chrome 24
    Firefox 17
    SmartGWT 3.1
    GWT 2.5

    #2
    DataSources assume that you do not want HTTP-level caching by default. To disable this, set dataSource/operationBinding.preventHttpCaching:false.

    At that point the 1970 date won't be involved, so Chrome's bug with combining two If-Modified-Since headers won't arise.

    Comment


      #3
      Thank you.

      For those following along at home. This added line fixed my problem:
      Code:
      ...
      		DataSource dataSource = new DataSource("rest/test/instances/by-status/finished/0/33");
      		dataSource.setRecordXPath("//DartTestInstance");
      
      		// Tada
      		dataSource.setPreventHTTPCaching(false);
      
      		DSRequest requestParams = new DSRequest();
      		HashMap<String, String> httpHeaders = new HashMap<String, String>();
      ...

      Comment

      Working...
      X