Processor - geronimo-iia/restexpress GitHub Wiki

We have three point when a "processor" can be applied:

  • pre processor: applied before response processing
  • post processor, applied after response processing
  • finally processor: always applied after serialization process

Actually, your could find:

  • HttpBasicAuthenticationPreprocessor
  • CacheHeaderPostprocessor
  • DateHeaderPostprocessor
  • EtagHeaderPostprocessor
  • LastModifiedHeaderPostprocessor
  • ResponseHeaderPostProcessor

HttpBasicAuthenticationPreprocessor

This preprocessor implements HTTP Basic authentication. It simply parses the Authorization header, putting the username and password in request headers. To use it, simply add it to your RestExpress server as follows:

server.addPreprocessor(new HttpBasicAuthenticationPreprocessor("my realm"));

Once this preprocessor completes successfully, it places the username and password in the request as headers, X-AuthenticatedUser and X-AuthenticatedPassword, respectively.

If the preprocessor fails, it throws an UnauthorizedException, which results in an HTTP status of 401 to the caller. It also sets the WWW-Authenticate header to 'Basic realm=' where is the arbitrary realm name passed in on instantiation.

Use of this preprocessor assumes you'll implement an authorization preprocessor that validates the username and password.

CacheHeaderPostprocessor

For GET and HEAD requests, adds caching control headers. May be used in conjunction with DateHeaderPostprocessor to add Date header for GET and HEAD requests.

If the route has a Parameters.Cache.MAX_AGE parameter, whose value is the max-age in seconds then the following are added:

  • Cache-Control: max-age=
  • Expires: now + max-age

If the route has a Flags.Cache.NO_CACHE flag, then the following headers are set on the response:

  • Cache-Control: no-cache
  • Pragma: no-cache

The MAX_AGE parameter takes precidence, in that, if present, the NO_CACHE flag is ignored.

To use: simply add server.addPostprocessor(new CacheHeaderPostprocessor()); in your main() method.

DateHeaderPostprocessor

For GET and HEAD requests, adds a Date: header, if not already present. This enables clients to determine age of a representation for caching purposes. is in RFC1123 full date format.

To use: simply add server.addPostprocessor(new DateHeaderPostprocessor()); in your main() method.

Note that HEAD requests are not provided with a Date header via this postprocessor. This is due to the fact that most external caches forward HEAD requests to the origin server as a GET request and cache the result.

EtagHeaderPostprocessor

If the response body is non-null, adds an ETag header. ETag is computed from the body object's hash code .

LastModifiedHeaderPostprocessor

Add header "LAST_MODIFIED" for GET requests if not present. Timestamp came from response body, if the object implement TimeStamped interface.

public interface TimeStamped {

    public Date updateAt();
}

ResponseHeaderPostProcessor

Add response header if they're not present. Headers are arbitrary define by pair (name, value).

To use: add server.addPostprocessor(new ResponseHeaderPostProcessor(name, value)); in your main() method.

⚠️ **GitHub.com Fallback** ⚠️