View Source cowmachine_util (cowmachine v1.10.3)

Utilities for parsing, quoting, and negotiation.

Link to this section Summary

Functions

Select the best fitting character set or none
Select the best fitting encoding or none
Match the Accept request header with content_types_provided.
Return the Content-Type for the response.
If there is no acceptable/available match, return the atom none.
AcceptHead is the value of the request's Accept header.
Provided is a list of media types the controller can provide:
  • a binary e.g. — <<"text/html">>
  • a binary and parameters e.g. — {<<"text/html">>,[{<<"level">>,<<"1">>}]}
  • two binaries e.g. {<<"text">>, <<"html">>}
  • two binaries and parameters e.g. — {<<"text">>,<<"html">>,[{<<"level">>,<<"1">>}]}
(the plain string case with no parameters is much more common)
Parse the HTTP date (IMF-fixdate, rfc850, asctime).
Match the Content-Type request header with content_types_accepted against.
Check header valid characters, see rfc822
Check if the given value is acceptaple for a http header value.
Parse a Content-Type like header, return the main Content-Type and a property list of options.
Parse an application/x-www-form-urlencoded string.
See also specification.
Check if the given location is safe to use as a location header. This is uses as a defense against urls with scripts. The test is quite strict and will drop values that might have been acceptable.

Link to this section Functions

Link to this function

choose_charset(CSets, AccCharHdr)

View Source
-spec choose_charset(CSets, AccCharHdr) -> Result
                  when CSets :: [binary()], AccCharHdr :: binary(), Result :: none | binary().
Select the best fitting character set or none
Link to this function

choose_encoding(Encs, AccEncHdr)

View Source
-spec choose_encoding(Encs, AccEncHdr) -> Result
                   when Encs :: [binary()], AccEncHdr :: binary(), Result :: none | binary().
Select the best fitting encoding or none
Link to this function

choose_media_type_accepted(ContentTypesAccepted, ReqHeader)

View Source
-spec choose_media_type_accepted(ContentTypesAccepted, ReqHeader) -> Result
                              when
                                  ContentTypesAccepted :: [cowmachine_req:media_type()],
                                  ReqHeader :: cow_http_hd:media_type(),
                                  Result :: cowmachine_req:media_type() | none.
Link to this function

choose_media_type_provided(Provided, AcceptHead)

View Source
-spec choose_media_type_provided(Provided, AcceptHead) -> Result
                              when
                                  Provided :: MediaTypes,
                                  MediaTypes :: [MediaType],
                                  MediaType :: cow_http_hd:media_type(),
                                  AcceptHead :: binary(),
                                  Result :: cow_http_hd:media_type() | none.
Match the Accept request header with content_types_provided.
Return the Content-Type for the response.
If there is no acceptable/available match, return the atom none.
AcceptHead is the value of the request's Accept header.
Provided is a list of media types the controller can provide:
  • a binary e.g. — <<"text/html">>
  • a binary and parameters e.g. — {<<"text/html">>,[{<<"level">>,<<"1">>}]}
  • two binaries e.g. {<<"text">>, <<"html">>}
  • two binaries and parameters e.g. — {<<"text">>,<<"html">>,[{<<"level">>,<<"1">>}]}
(the plain string case with no parameters is much more common)
Link to this function

convert_request_date(Date)

View Source
-spec convert_request_date(Date) -> Result when Date :: binary(), Result :: calendar:datetime().
Parse the HTTP date (IMF-fixdate, rfc850, asctime).
Link to this function

format_content_type(MediaType)

View Source
-spec format_content_type(MediaType) -> Result
                       when MediaType :: cow_http_hd:media_type(), Result :: binary().
Link to this function

is_media_type_accepted(ContentTypesAccepted, ContentTypeReqHeader)

View Source
-spec is_media_type_accepted(ContentTypesAccepted, ContentTypeReqHeader) -> Result
                          when
                              ContentTypesAccepted :: list(),
                              ContentTypeReqHeader :: cow_http_hd:media_type(),
                              Result :: boolean().
Match the Content-Type request header with content_types_accepted against.
-spec is_valid_header(Header) -> Result when Header :: binary(), Result :: boolean().
Check header valid characters, see rfc822
Link to this function

is_valid_header_value(Header)

View Source
-spec is_valid_header_value(Header) -> Result when Header :: binary(), Result :: boolean().
Check if the given value is acceptaple for a http header value.
Link to this function

normalize_content_type(Type)

View Source
-spec normalize_content_type(Type) -> Result
                          when
                              Type :: cowmachine_req:media_type(),
                              Result :: cow_http_hd:media_type().
-spec parse_header(String) -> Result
                when String :: binary(), Result :: {binary(), [{binary(), binary()}]}.
Parse a Content-Type like header, return the main Content-Type and a property list of options.
-spec parse_qs(String) -> Result when String :: binary(), Result :: [{binary(), binary()}].
Parse an application/x-www-form-urlencoded string.
See also specification.
-spec quoted_string(String) -> Result when String :: binary(), Result :: binary().
Link to this function

split_quoted_strings(String)

View Source
-spec split_quoted_strings(String) -> Result when String :: binary(), Result :: [binary()].
Link to this function

valid_location(Location)

View Source
-spec valid_location(Location) -> Result when Location :: binary(), Result :: {true, binary()} | false.
Check if the given location is safe to use as a location header. This is uses as a defense against urls with scripts. The test is quite strict and will drop values that might have been acceptable.