Interface EntityTags
public interface EntityTags
Provides services for validating "If-Match" and
"If-None-Match" request headers.
Also provides a facility for generating an "ETag" header
automatically from a secure digest of a
HttpServletResponse.- Author:
- cdivilly
-
Nested Class Summary
Nested Classes -
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionbuilder()Return a new instance of anEntityTag.BuilderThis method formats a textual value into a digested, strongEntityTagvalue.Parses anEntityTagvalue from the specified header.booleanetag(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, HasGetMethod servlet) Adapt aHttpServletResponseto produce a strong "ETag" generated from a secure digest of the response headers and body.booleanetag(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, HasGetMethod servlet, EntityTags.EntityTagType etagType) Adapt aHttpServletResponseto produce a strong "ETag" generated from a secure digest of the response headers and body.booleanhasPrecondition(javax.servlet.http.HttpServletRequest request) Determine if the specified request is a conditional HTTP request.booleanhasPrecondition(javax.servlet.http.HttpServletRequest request, EntityTags.EntityTagType etagType) Determine if the specified request is a conditional HTTP request.parse(CharSequence text) Parses text into anEntityTagvalue.voidvalidatePrecondition(javax.servlet.http.HttpServletRequest request, CharSequence currentEntityTag) Validate whether the pre-condition in the request matches the current "ETag" value of the requested resource.
-
Field Details
-
IF_MATCH
- See Also:
-
IF_NONE_MATCH
- See Also:
-
ETAG
- See Also:
-
-
Method Details
-
hasPrecondition
boolean hasPrecondition(javax.servlet.http.HttpServletRequest request) Determine if the specified request is a conditional HTTP request. A request is conditional if it containsIF_MATCHfor a PUT,POST,PATCH or DELETE method, andIF_NONE_MATCHfor a GET or HEAD method- Parameters:
request- The HTTP request to check for presence of a pre-condition- Returns:
- true if request has a precondition, false otherwise
-
hasPrecondition
boolean hasPrecondition(javax.servlet.http.HttpServletRequest request, EntityTags.EntityTagType etagType) Determine if the specified request is a conditional HTTP request. A request is conditional if it containsIF_MATCHfor a PUT,POST,PATCH or DELETE method, andIF_NONE_MATCHfor a GET or HEAD method- Parameters:
request- The HTTP request to check for presence of a pre-conditionetagType- The type of the EntityTag- Returns:
- true if request has a precondition, false otherwise
-
validatePrecondition
void validatePrecondition(javax.servlet.http.HttpServletRequest request, CharSequence currentEntityTag) Validate whether the pre-condition in the request matches the current "ETag" value of the requested resource.- Parameters:
request- The request to be validatedcurrentEntityTag- The current "ETag" value of the requested resource
-
parse
Parses text into anEntityTagvalue. The value must be correctly formatted as a quoted ETag value.- Parameters:
text- The text value to parse- Returns:
- EntityTag instance, or null if the supplied parameter is null or "*"
- Throws:
IllegalArgumentException- if the value is not correctly formatted
-
entityTag
This method formats a textual value into a digested, strongEntityTagvalue. This method is equivalent to:String text = ...; EntityTags tags = ...; EntityTag tag = tags.builder().append(text).build();
-
entityTag
Parses anEntityTagvalue from the specified header. If the header is "If-Match" orIF_NONE_MATCHand the value is*then a null value will be returned.- Parameters:
request- The request to examineheaderName- The name of the HTTP Header- Returns:
- The
EntityTagvalue or null if the header is absent or has no value
-
builder
EntityTag.Builder builder()Return a new instance of anEntityTag.Builder- Returns:
EntityTag.Builderinstance
-
etag
boolean etag(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, HasGetMethod servlet, EntityTags.EntityTagType etagType) throws javax.servlet.ServletException, IOException Adapt aHttpServletResponseto produce a strong "ETag" generated from a secure digest of the response headers and body. This method also performs any validation This provides a simple mechanism to produce a guaranteed correct "ETag", however the simplicity has some costs:- The CPU overhead of generating the secure digest
- The memory overhead of buffering the entire response in order to produce the digest
HasGetMethodinterface and pass a reference to themselves as the final parameter.- Parameters:
request- The request being processedresponse- The response object provided by the servlet containerservlet- The servlet which will produce the responseetagType- The type of the EntityTag- Returns:
- true if the servlet should proceed with processing the request, false otherwise
- Throws:
javax.servlet.ServletException- if the HTTP request cannot be handledIOException- if an input or output error occurs while the request is being handled- See Also:
-
etag
boolean etag(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, HasGetMethod servlet) throws javax.servlet.ServletException, IOException Adapt aHttpServletResponseto produce a strong "ETag" generated from a secure digest of the response headers and body. This method also performs any validation This provides a simple mechanism to produce a guaranteed correct "ETag", however the simplicity has some costs:- The CPU overhead of generating the secure digest
- The memory overhead of buffering the entire response in order to produce the digest
HasGetMethodinterface and pass a reference to themselves as the final parameter. All methods will be processed- Parameters:
request- The request being processedresponse- The response object provided by the servlet containerservlet- The servlet which will produce the response- Returns:
- true if the servlet should proceed with processing the request, false otherwise
- Throws:
javax.servlet.ServletException- if the HTTP request cannot be handledIOException- if an input or output error occurs while the request is being handled- See Also:
-