[−][src]Struct webmachine_rust::WebmachineResource
Struct to represent a resource in webmachine
Fields
finalise_response: Option<Box<dyn Fn(&mut WebmachineContext)>>
This is called just before the final response is constructed and sent. It allows the resource an opportunity to modify the response after the webmachine has executed.
render_response: Box<dyn Fn(&mut WebmachineContext) -> Option<String>>
This is invoked to render the response for the resource
available: Box<dyn Fn(&mut WebmachineContext) -> bool>
Is the resource available? Returning false will result in a '503 Service Not Available' response. Defaults to true. If the resource is only temporarily not available, add a 'Retry-After' response header.
known_methods: Vec<String>
HTTP methods that are known to the resource. Default includes all standard HTTP methods. One could override this to allow additional methods
uri_too_long: Box<dyn Fn(&mut WebmachineContext) -> bool>
If the URI is too long to be processed, this should return true, which will result in a
allowed_methods: Vec<String>
HTTP methods that are allowed on this resource. Defaults to GET','HEAD and 'OPTIONS'.
malformed_request: Box<dyn Fn(&mut WebmachineContext) -> bool>
If the request is malformed, this should return true, which will result in a '400 Malformed Request' response. Defaults to false.
Is the client or request not authorized? Returning a Some
forbidden: Box<dyn Fn(&mut WebmachineContext) -> bool>
Is the request or client forbidden? Returning true will result in a '403 Forbidden' response. Defaults to false.
unsupported_content_headers: Box<dyn Fn(&mut WebmachineContext) -> bool>
If the request includes any invalid Content-* headers, this should return true, which will result in a '501 Not Implemented' response. Defaults to false.
acceptable_content_types: Vec<String>
The list of acceptable content types. Defaults to 'application/json'. If the content type of the request is not in this list, a '415 Unsupported Media Type' response is returned.
valid_entity_length: Box<dyn Fn(&mut WebmachineContext) -> bool>
If the entity length on PUT or POST is invalid, this should return false, which will result in a '413 Request Entity Too Large' response. Defaults to true.
finish_request: Box<dyn Fn(&mut WebmachineContext, &WebmachineResource)>
This is called just before the final response is constructed and sent. This allows the response to be modified. The default implementation adds CORS headers to the response
options: Box<dyn Fn(&mut WebmachineContext, &WebmachineResource) -> Option<HashMap<String, Vec<String>>>>
If the OPTIONS method is supported and is used, this return a HashMap of headers that
produces: Vec<String>
The list of content types that this resource produces. Defaults to 'application/json'. If more than one is provided, and the client does not supply an Accept header, the first one will be selected.
languages_provided: Vec<String>
The list of content languages that this resource provides. Defaults to an empty list, which represents all languages. If more than one is provided, and the client does not supply an Accept-Language header, the first one will be selected.
charsets_provided: Vec<String>
The list of charsets that this resource provides. Defaults to an empty list, which represents all charsets with ISO-8859-1 as the default. If more than one is provided, and the client does not supply an Accept-Charset header, the first one will be selected.
encodings_provided: Vec<String>
The list of encodings your resource wants to provide. The encoding will be applied to the response body automatically by Webmachine. Default includes only the 'identity' encoding.
variances: Vec<String>
The list of header names that should be included in the response's Vary header. The standard content negotiation headers (Accept, Accept-Encoding, Accept-Charset, Accept-Language) do not need to be specified here as Webmachine will add the correct elements of those automatically depending on resource behavior. Default is an empty list.
resource_exists: Box<dyn Fn(&mut WebmachineContext) -> bool>
Does the resource exist? Returning a false value will result in a '404 Not Found' response unless it is a PUT or POST. Defaults to true.
previously_existed: Box<dyn Fn(&mut WebmachineContext) -> bool>
If this resource is known to have existed previously, this should return true. Default is false.
moved_permanently: Box<dyn Fn(&mut WebmachineContext) -> Option<String>>
If this resource has moved to a new location permanently, this should return the new location as a String. Default is to return None
moved_temporarily: Box<dyn Fn(&mut WebmachineContext) -> Option<String>>
If this resource has moved to a new location temporarily, this should return the new location as a String. Default is to return None
is_conflict: Box<dyn Fn(&mut WebmachineContext) -> bool>
If this returns true, the client will receive a '409 Conflict' response. This is only called for PUT requests. Default is false.
allow_missing_post: Box<dyn Fn(&mut WebmachineContext) -> bool>
Return true if the resource accepts POST requests to nonexistent resources. Defaults to false.
generate_etag: Box<dyn Fn(&mut WebmachineContext) -> Option<String>>
If this returns a value, it will be used as the value of the ETag header and for comparison in conditional requests. Default is None.
last_modified: Box<dyn Fn(&mut WebmachineContext) -> Option<DateTime<FixedOffset>>>
Returns the last modified date and time of the resource which will be added as the Last-Modified header in the response and used in negotiating conditional requests. Default is None
delete_resource: Box<dyn Fn(&mut WebmachineContext) -> Result<bool, u16>>
Called when a DELETE request should be enacted. Return Ok(true)
if the deletion succeeded,
and Ok(false)
if the deletion was accepted but cannot yet be guaranteed to have finished.
If the delete fails for any reason, return an Err with the status code you wish returned
(a 500 status makes sense).
Defaults to Ok(true)
.
post_is_create: Box<dyn Fn(&mut WebmachineContext) -> bool>
If POST requests should be treated as a request to put content into a (potentially new)
resource as opposed to a generic submission for processing, then this should return true.
If it does return true, then create_path
will be called and the rest of the request will
be treated much like a PUT to the path returned by that call. Default is false.
process_post: Box<dyn Fn(&mut WebmachineContext) -> Result<bool, u16>>
If post_is_create
returns false, then this will be called to process any POST request.
If it succeeds, return Ok(true)
, Ok(false)
otherwise. If it fails for any reason,
return an Err with the status code you wish returned (e.g., a 500 status makes sense).
Default is false. If you want the result of processing the POST to be a redirect, set
context.redirect
to true.
create_path: Box<dyn Fn(&mut WebmachineContext) -> Result<String, u16>>
This will be called on a POST request if post_is_create
returns true. It should create
the new resource and return the path as a valid URI part following the dispatcher prefix.
That path will replace the previous one in the return value of WebmachineRequest.request_path
for all subsequent resource function calls in the course of this request and will be set
as the value of the Location header of the response. If it fails for any reason,
return an Err with the status code you wish returned (e.g., a 500 status makes sense).
Default will return an Ok(WebmachineRequest.request_path)
. If you want the result of
processing the POST to be a redirect, set context.redirect
to true.
process_put: Box<dyn Fn(&mut WebmachineContext) -> Result<bool, u16>>
This will be called to process any PUT request. If it succeeds, return Ok(true)
,
Ok(false)
otherwise. If it fails for any reason, return an Err with the status code
you wish returned (e.g., a 500 status makes sense). Default is Ok(true)
multiple_choices: Box<dyn Fn(&mut WebmachineContext) -> bool>
If this returns true, then it is assumed that multiple representations of the response are possible and a single one cannot be automatically chosen, so a 300 Multiple Choices will be sent instead of a 200. Default is false.
expires: Box<dyn Fn(&mut WebmachineContext) -> Option<DateTime<FixedOffset>>>
If the resource expires, this should return the date/time it expires. Default is None.
Trait Implementations
impl Default for WebmachineResource
[src]
fn default() -> WebmachineResource
[src]
Creates a default webmachine resource
Auto Trait Implementations
impl !RefUnwindSafe for WebmachineResource
impl !Send for WebmachineResource
impl !Sync for WebmachineResource
impl Unpin for WebmachineResource
impl !UnwindSafe for WebmachineResource
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,