response.headers.ETag undefined

Oct 6, 2012 at 4:09 PM
Edited Oct 6, 2012 at 6:00 PM

Hello,

I use the SharePoint 2010 odata service (which is a version 1 odata service). When I send an update using POST with X-HTTP-METHOD MERGE I can see using fiddler that I get a successful HTTP 204 No Content response with a new value for the concurrency token in the ETag http response header.

HTTP/1.1 204 No Content
Cache-Control: no-cache
ETag: W/"2"
Server: Microsoft-IIS/7.5
SPRequestGuid: 1f93ae70-a787-4d07-b1e8-8711c165334f
X-SharePointHealthScore: 0
DataServiceVersion: 1.0;
X-AspNet-Version: 2.0.50727
WWW-Authenticate: Negotiate oRswGaADCgEAoxIEEAEAAABDh+CIwTbjqQAAAAA=
Persistent-Auth: true
X-Powered-By: ASP.NET
MicrosoftSharePointTeamServices: 14.0.0.6120
X-MS-InvokeApp: 1; RequireReadOnly
Date: Sat, 06 Oct 2012 14:51:40 GMT

However, when I try to get at this new value for the concurrency token using response.headers.ETag it is undefined. In fact, response.headers is an empty array [].

Is this a problem with datajs? I found the same problem using jquery.ajax. So perhaps the problem is the XMLHttpRequest / ActiveXObject that does not pass back any response http headers when the http response is 204 No Content. 

My workaround for now is to immediately reload the object after the successful update (since the SharePoint odata service is version 1 I cannot send a prefer http header with value return-content, but even if I could send a prefer header the service may not honor this request to return content anyway). What I really need is to read the ETag response http header. 

Here is the code:

function requestUpdate(model, selector) {
    var deferred = new $.Deferred();
    OData.request({
        requestUri: model.__metadata.uri,
        method: "POST",
        data: selector ? selector(model) : model,
        headers: {
            "If-Match": model.__metadata.etag,
            "X-HTTP-Method": "MERGE"
        }
    }, function (data, response) {
        model.__metadata.etag = response.headers.ETag;
        deferred.resolve({ d: model });
    }, function (error) {
        deferred.reject(error);
    });
    return deferred.promise();
}
Oct 6, 2012 at 5:58 PM

I just tested this in Chrome and it works ok in Chrome. So for now it appears to just not work in Internet Explorer 9 on Windows Server 2008 R2

Oct 16, 2012 at 8:33 PM

Hi Remco,

    No, this is by design so far.  The endpoint may send an ETag in the payload... for now, if it comes as a response header datajs will ignore it. You will have to pick it up as per the code above.  What error are you facing in IE9, is it throwing an error?

Thanks,

Alex Trigo.

Oct 16, 2012 at 8:40 PM

Hi Alex,

In IE9 response.headers is an empty array [] and therefore response.headers.ETag is undefined. No error thrown. I'm a bit confused why you say this is by design as it works ok in Chrome. In Chrome response.headers is an object with an ETag property with the correct new value  of the concurrency token. 

thanks

Remco

Oct 16, 2012 at 10:36 PM

Hi Remco,

   Sorry If didn't explain myself properly.  What is by design is that the etag doesn't show up inside __metadata.  That is because  it may be sent by the endpoint as part of the payload.  The fact the headers array is coming back as empty in IE9 is not by design. Thanks for letting us know I will investigate.  Which version of datajs are you using?

Thanks,

Alex Trigo.

Oct 17, 2012 at 8:58 AM

Hi Alex,

It's version 1.0.3

thanks

Remco

 

Nov 12, 2012 at 1:25 AM

There's a bug in IE8/9. It drops all headers if it gets a 204 response.

do a google on IE0013: IE XMLHTTP implementation turns 204 response code into bogus 1223 status code

Russell