I'm programmatically downloading a file from a Sharepoint 2016 document library. The URL goes:
https://hostname.com/Site/Folder/_layouts/15/download.aspx?{long, long URL}
The site emits the ETag header, but when I send a request with an If-None-Match, providing the ETag I just got, there's no 304 Not Modified response, it's 200 and the whole document again.
The ETag header I'm receiving goes:
ETag: "{EED54197-A30B-4625-9EBA-8DC7F9D62CF3},1435"
The request header then goes:
If-None-Match: "{EED54197-A30B-4625-9EBA-8DC7F9D62CF3},1435"
I'm testing the same setup against a static file in IIS - it works as expected, 304 comes.
What am I missing, please? Could it be an oversight in the Sharepoint API?
EDIT: one unsatisfactory workaround involves firing a HEAD request first and manually matching the ETag values on the client.
Related
If I have configured Access-Control-Allow-Origin: http://mydomain correctly, should it be listed in the response headers if I view them using the web developer plugin? I don't see it. Should it be there?
I have tried viewing the response headers after submitting my post request, and just calling the page.
Background
I need to transfer a couple of values from mydomain to receivingdomain via XMLHttpRequest POST request and am trying to troubleshoot
XMLHttpRequest Page1.asp cannot load https://receivingdomain. No Access-Control-Allow-Origin header is present on the requested resource
If I turn on the Allow-Control-Allow-Extension plug-in my post requests work correctly. However, when this plug-in is disabled, my post requests are being received ok (the data is inserted into the database) - I'm just not getting any result back from the receiving server.
On a XPage, when I want to display an image which is stored as a file attachment of a NotesDocument, I define the image source as follows: [UNID_OF_FILE]/$FILE/[NAME_OF_ATTACHMENT].
Whenever a page contains this kind of source, a HTTP request is performed. Since there is no "Expires" date defined in the response headers, the HTTP status is (in best case) "304 Not Modified", which means that the attachment is not again loaded from the server. However, this is still a HTTP request that increases the page's loading time. Is there a way to set the expiration date for these responses to get a HTTP status "200 OK (Cache)" which does not perform a HTTP request and directly loads the image ressource from the cache?
PS: I know I could create a "helper" XPage (for downloading this file attachment) which manually sets the response headers with facesContext.getExternalContext().getResponse().setHeader(...) etc. Yet this would mean that I would have to largely rewrite my XPages application. I hope that there are some server or database settings that allow to directly set the corresponding response headers.
You can add a Web Site Rule that sets the Expires header (and other HTTP headers).
Here's an example of a web site rule that sets the Expires header to 14 days for all files of type jpg:
I am optimizing an Express JSON API for consumption by iOS & Android Apps and do not seem to be able to get Express to respond with the correct 304 header when the Apps specify an etag within the If-None-Match header.
I needn't setup Etag generation as Express was already providing those; however when the Apps specify that etag again in a second request; Express' response is still a 200 with the data, as you can see in my tests in Postman:
How can I enable this functionality?
Update: The iOS dev is seeing the correct 304 Not Modified responses from the Express server but I don't understand why I am not seeing them within Postman - Does Postman support such actions?
I just stumble across this today, you need to disable Postman default behaviour of sending Cache-Control as none. To do this just go to settings change Send no-cache header to No.
Does the browser make a new request to the location given in the header?
I ask because I was playing around with Fiddler and noticed when I make a request to a page that returns a 302 HTTP code, there are two entries in the network log. The first is to the initial URL, and the second is to the new location given in the response header of the first request.
I'm just curious if web browsers work the same way, but just hide the first response from the user.
Yes, the browser works in very much similar fashion. You can try requesting a url in Chrome, possibly the one you tried in Fiddler. The Network Log of chrome would show you two requests.
The RFC description of HTTP status code can be read over here,
Quoting from there only, regarding the 302 status code:
RFC 1945 and RFC 2068 specify that the client is not allowed
to change the method on the redirected request. However, most
existing user agent implementations treat 302 as if it were a 303
response, performing a GET on the Location field-value regardless
of the original request method. The status codes 303 and 307 have
been added for servers that wish to make unambiguously clear which
kind of reaction is expected of the client.
When a server responds with a 302 status code, it send back the newer url (to which the current requested old url is to be redirected) to the requesting user-agent (likely a browser). Now, as per the RFC document, the user agent must not request the newer url for 302 status code. Yet most of them do make a second request.
Hope-this-helps.
I am making a a request to an image and the response headers that I get back are:
Accept-Ranges:bytes
Content-Length:4499
Content-Type:image/png
Date:Tue, 24 May 2011 20:09:39 GMT
ETag:"0cfe867f5b8cb1:0"
Last-Modified:Thu, 20 Jan 2011 22:57:26 GMT
Server:Microsoft-IIS/7.5
X-Powered-By:ASP.NET
Note the absence of the Cache-Control header.
On subsequent requests on Chrome, Chrome knows to go to the cache to retrieve the image. How does it know to use the cache? I was under the impression that I would have to tell it with the Cache-Control header.
You have both an ETag and a Last-Modified header. It probably uses those. But for that to happen, it still needs to make a request with If-None-Match or If-Modified-Since respectively.
To set the Cache-Control You have to specify it yourself. You can either do it in web.config , IIS Manager for selected folders (static, images ...) or set it in code. The HTTP 1.1 standard recommends one year in future as the maximum expiration time.
Setting expiration date one year in future is considered good practice for all static content in your site. Not having it in headers results in If-Modified-Since requests which can take longer then first time requests for small static files. In these calls ETag header is used.
When You have Cache-Control: max-age=315360000 basic HTTP responses will outnumber If-Modified-Since> calls and because of that it is good to remove ETag header and result in smaller static file response headers. IIS doesn't have setting for that so You have to do response.Headers.Remove("ETag"); in OnPreServerRequestHeaders()
And if You want to optimize Your headers further You can remove X-Powered-By:ASP.NET in IIS settings and X-Aspnet-Version header (altough I don't see in Your response) in web.config - enableVersionHeader="false" in system.web/httpRuntime element.
For more tips I suggest great book - http://www.amazon.com/Ultra-Fast-ASP-NET-Build-Ultra-Scalable-Server/dp/1430223839