How do I know when I can send a Not Modified Response via 304?
server_etag = gen_etag_for_this_file(myfile) etag_from_browser = get_header("Etag") if etag_from_browser does not exist: etag_from_browser = get_header("If-None-Match") if the browser has quoted the etag: strip the quotes (e.g. "foo" --> foo) set server_etag into http header if etag_from_browser matches server_etag send 304 return code to browser
/* the client should set either Etag or If-None-Match */ /* some clients quote the parm, strip quotes if so */ mketag(etag, &sb); etagin = apr_table_get(r->headers_in, "Etag"); if (etagin == NULL) etagin = apr_table_get(r->headers_in, "If-None-Match"); if (etag != NULL && etag[0] == """) { int sl; sl = strlen(etag); memmove(etag, etag+1, sl+1); etag[sl-2] = 0; logit(2,"etag=:%s:",etag); } ... apr_table_add(r->headers_out, "ETag", etag); ... if (etagin != NULL && strcmp(etagin, etag) == 0) { /* if the etag matches, we return a 304 */ rc = HTTP_NOT_MODIFIED; }
Tags: language-agnostic http
Source: By tags2k as answer to the question
This code snippet was collected from stackoverflow, and is licensed under CC BY-SA 3.0
Related code-snippets:
- How can I get the value of in a loop?
- Function for creating color wheels.
- Why use unsigned values over signed ones?
- Generate list of all possible permutations of a string.
- How can I use combinations of sets as test data?
- Format string to title case. Title case is a common text format in English.
- How can we efficiently get sorted sums of a sorted list?
- How can I make my projects international in india?
- A little diversion into floating point (im)precision, part 1 | 1 – 0 | 1 | 1 | 1 | 1 | 1 | 1 | 2 | 1 | 1 | 2 | 1 | 2 | 1 | 1 | 2 | 1 | 2 | 3 | 4 | A little diversion into floating point (im)precision, part 1 | 3 | 4 | 5 | 5 | 8 | 8 | 2 | 3 | 4 | 7 | 8 | 7 | 7 | 7 | 6 | 1 | 1 | 5 | 1
- I am using the directx x or opengl to create 100 floating cubes. Is this possible?
- "Sorting" colors by distinctiveness. Followup:
- How can I modify a.xfdl file?
- Pass by reference or pass by value?
- How can I start using Version Control and Visual Studio?
- How do I curl a web page?