Commit 29605c02 authored by Geoff Simmons's avatar Geoff Simmons

More complete examples of ETag/I-N-M for .id() and .sha256().

parent 8b4f8e77
...@@ -488,13 +488,33 @@ BLOB xreader.id() ...@@ -488,13 +488,33 @@ BLOB xreader.id()
Returns a unique, opaque identifier for the state of the file as Returns a unique, opaque identifier for the state of the file as
determined when it was most recently checked. The ID changes if and determined when it was most recently checked. The ID changes if and
only if the file was found to have changed. only if the file was found to have changed. Invokes VCL failure if the
most recent update check encountered an error.
Example:: Example::
# Use the base64 encoding of .id() for the ETag response header, and
# send a 304 response if the If-None-Match request header matches
# it.
import blob; import blob;
set resp.http.ETag = blob.encode(BASE64, blob=rdr.id()); sub vcl_recv {
if (req.http.If-None-Match == blob.encode(BASE64, blob=rdr.id())) {
return (synth(304));
}
else {
return (synth(200));
}
}
sub vcl_synth {
set resp.http.ETag = blob.encode(BASE64, blob=rdr.id());
if (resp.status == 200) {
rdr.synth();
}
return(deliver);
}
The contents of the BLOB returned by ``.id()`` are intentionally not The contents of the BLOB returned by ``.id()`` are intentionally not
documented, and should not be relied on to extract information about documented, and should not be relied on to extract information about
...@@ -514,6 +534,9 @@ check encountered an error. ...@@ -514,6 +534,9 @@ check encountered an error.
Example:: Example::
# Use .sha256() for the ETag and If-None-Match headers, as shown
# above for .id().
import blob; import blob;
sub vcl_init { sub vcl_init {
...@@ -534,6 +557,7 @@ Example:: ...@@ -534,6 +557,7 @@ Example::
if (resp.status == 200) { if (resp.status == 200) {
rdr.synth(); rdr.synth();
} }
return(deliver);
} }
The ``.sha256()`` and ``.id()`` methods both return a digest for the The ``.sha256()`` and ``.id()`` methods both return a digest for the
......
...@@ -444,13 +444,33 @@ $Method BLOB .id() ...@@ -444,13 +444,33 @@ $Method BLOB .id()
Returns a unique, opaque identifier for the state of the file as Returns a unique, opaque identifier for the state of the file as
determined when it was most recently checked. The ID changes if and determined when it was most recently checked. The ID changes if and
only if the file was found to have changed. only if the file was found to have changed. Invokes VCL failure if the
most recent update check encountered an error.
Example:: Example::
# Use the base64 encoding of .id() for the ETag response header, and
# send a 304 response if the If-None-Match request header matches
# it.
import blob; import blob;
set resp.http.ETag = blob.encode(BASE64, blob=rdr.id()); sub vcl_recv {
if (req.http.If-None-Match == blob.encode(BASE64, blob=rdr.id())) {
return (synth(304));
}
else {
return (synth(200));
}
}
sub vcl_synth {
set resp.http.ETag = blob.encode(BASE64, blob=rdr.id());
if (resp.status == 200) {
rdr.synth();
}
return(deliver);
}
The contents of the BLOB returned by ``.id()`` are intentionally not The contents of the BLOB returned by ``.id()`` are intentionally not
documented, and should not be relied on to extract information about documented, and should not be relied on to extract information about
...@@ -467,6 +487,9 @@ check encountered an error. ...@@ -467,6 +487,9 @@ check encountered an error.
Example:: Example::
# Use .sha256() for the ETag and If-None-Match headers, as shown
# above for .id().
import blob; import blob;
sub vcl_init { sub vcl_init {
...@@ -487,6 +510,7 @@ Example:: ...@@ -487,6 +510,7 @@ Example::
if (resp.status == 200) { if (resp.status == 200) {
rdr.synth(); rdr.synth();
} }
return(deliver);
} }
The ``.sha256()`` and ``.id()`` methods both return a digest for the The ``.sha256()`` and ``.id()`` methods both return a digest for the
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment