[−][src]Struct webmachine_rust::WebmachineResource
Struct to represent a resource in webmachine
Fields
finalise_response: Option<WebmachineCallback<'a, ()>>
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: WebmachineCallback<'a, Option<String>>
This is invoked to render the response for the resource
available: WebmachineCallback<'a, 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<&'a str>
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: WebmachineCallback<'a, bool>
If the URI is too long to be processed, this should return true, which will result in a '414 Request URI Too Long' response. Defaults to false.
allowed_methods: Vec<&'a str>
HTTP methods that are allowed on this resource. Defaults to GET','HEAD and 'OPTIONS'.
malformed_request: WebmachineCallback<'a, 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: WebmachineCallback<'a, bool>
Is the request or client forbidden? Returning true will result in a '403 Forbidden' response. Defaults to false.
unsupported_content_headers: WebmachineCallback<'a, 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<&'a str>
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: WebmachineCallback<'a, 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: WebmachineCallback<'a, ()>
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: WebmachineCallback<'a, Option<HashMap<String, Vec<String>>>>
If the OPTIONS method is supported and is used, this returns a HashMap of headers that should appear in the response. Defaults to CORS headers.
produces: Vec<&'a str>
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<&'a str>
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<&'a str>
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<&'a str>
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<&'a str>
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: WebmachineCallback<'a, 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: WebmachineCallback<'a, bool>
If this resource is known to have existed previously, this should return true. Default is false.
moved_permanently: WebmachineCallback<'a, 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: WebmachineCallback<'a, 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: WebmachineCallback<'a, 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: WebmachineCallback<'a, bool>
Return true if the resource accepts POST requests to nonexistent resources. Defaults to false.
generate_etag: WebmachineCallback<'a, 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: WebmachineCallback<'a, 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: WebmachineCallback<'a, 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: WebmachineCallback<'a, 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: WebmachineCallback<'a, 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: WebmachineCallback<'a, 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: WebmachineCallback<'a, 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: WebmachineCallback<'a, 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: WebmachineCallback<'a, Option<DateTime<FixedOffset>>>
If the resource expires, this should return the date/time it expires. Default is None.
Trait Implementations
impl<'a> Clone for WebmachineResource<'a>
[src]
pub fn clone(&self) -> WebmachineResource<'a>
[src]
pub fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl<'a> Default for WebmachineResource<'a>
[src]
pub fn default() -> WebmachineResource<'a>
[src]
Auto Trait Implementations
impl<'a> RefUnwindSafe for WebmachineResource<'a>
[src]
impl<'a> Send for WebmachineResource<'a>
[src]
impl<'a> Sync for WebmachineResource<'a>
[src]
impl<'a> Unpin for WebmachineResource<'a>
[src]
impl<'a> UnwindSafe for WebmachineResource<'a>
[src]
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,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T> Instrument for T
[src]
pub fn instrument(self, span: Span) -> Instrumented<Self>
[src]
pub fn in_current_span(self) -> Instrumented<Self>
[src]
impl<T> Instrument for T
[src]
pub fn instrument(self, span: Span) -> Instrumented<Self>
[src]
pub fn in_current_span(self) -> Instrumented<Self>
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn clone_into(&self, target: &mut T)
[src]
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.
pub 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>,