View Source httpd_util (inets v9.2)

Miscellaneous utility functions to be used when implementing Erlang web server API modules.

This module provides the Erlang web server API module programmer with miscellaneous utility functions.

Note

Note the module is only recommended for using with httpd - for other cases it should be considered as deprecated.

SEE ALSO

httpd

Summary

Functions

convert_request_date(DateString) -> ErlDate|bad_date

create_etag(FileInfo) -> Etag

day(NthDayOfWeek) -> DayOfWeek

lookup(ETSTable,Key,Undefined) -> Result

lookup_mime(ConfigDB,Suffix,Undefined) -> MimeType

lookup_mime_default(ConfigDB,Suffix,Undefined) -> MimeType

message(StatusCode,PhraseArgs,ConfigDB) -> Message

month(NthMonth) -> Month

multi_lookup(ETSTable,Key) -> Result

reason_phrase(StatusCode) -> Description

rfc1123_date(Date) -> RFC1123Date

split(String,RegExp,N) -> SplitRes

split_path(RequestLine) -> {Path,QueryStringOrPathInfo}

split_script_path(RequestLine) -> Split

Functions

convert_request_date(DateString) -> ErlDate|bad_date

convert_request_date/1 converts DateString to the Erlang date format. DateString must be in one of the three date formats defined in RFC 2616.

create_etag(FileInfo) -> Etag

create_etag/1 calculates the Etag for a file from its size and time for last modification. FileInfo is a record defined in kernel/include/file.hrl.

day(NthDayOfWeek) -> DayOfWeek

day/1 converts the day of the week (NthDayOfWeek) from an integer (1-7) to an abbreviated string, that is:

1 = "Mon", 2 = "Tue", ..., 7 = "Sat".

Equivalent to lookup/3

Link to this function

lookup(Table, Key, Undefined)

View Source

lookup(ETSTable,Key,Undefined) -> Result

lookup extracts {Key,Value} tuples from ETSTable and returns the Value associated with Key. If ETSTable is of type bag, only the first Value associated with Key is returned. lookup/2 returns undefined and lookup/3 returns Undefined if no Value is found.

Link to this function

lookup_mime(ConfigDB, Suffix)

View Source

Equivalent to lookup_mime/3

Link to this function

lookup_mime(ConfigDB, Suffix, Undefined)

View Source

lookup_mime(ConfigDB,Suffix,Undefined) -> MimeType

lookup_mime returns the MIME type associated with a specific file suffix as specified in the file mime.types (located in the config directory).

Link to this function

lookup_mime_default(ConfigDB, Suffix)

View Source

Equivalent to lookup_mime_default/3

Link to this function

lookup_mime_default(ConfigDB, Suffix, Undefined)

View Source

lookup_mime_default(ConfigDB,Suffix,Undefined) -> MimeType

lookup_mime_default returns the MIME type associated with a specific file suffix as specified in the mime.types file (located in the config directory). If no appropriate association is found, the value of DefaultType is returned.

message(StatusCode,PhraseArgs,ConfigDB) -> Message

message/3 returns an informative HTTP 1.1 status string in HTML. Each StatusCode requires a specific PhraseArgs:

  • 301 - string/0: A URL pointing at the new document position.

  • 400 | 401 | 500 - none (no PhraseArgs).

  • 403 | 404 - string/0: A Request-URI as described in RFC 2616.

  • 501 - {Method,RequestURI,HTTPVersion}: The HTTP Method, Request-URI, and HTTP-Version as defined in RFC 2616.

  • 504 - string/0: A string describing why the service was unavailable.

month(NthMonth) -> Month

month/1 converts the month NthMonth as an integer (1-12) to an abbreviated string, that is:

1 = "Jan", 2 = "Feb", ..., 12 = "Dec".

Link to this function

multi_lookup(Table, Key)

View Source

multi_lookup(ETSTable,Key) -> Result

multi_lookup extracts all {Key,Value} tuples from an ETSTable and returns all Values associated with Key in a list.

reason_phrase(StatusCode) -> Description

reason_phrase returns Description of an HTTP 1.1 StatusCode, for example, 200 is "OK" and 201 is "Created". For more information, see RFC 2616.

Equivalent to rfc1123_date/1

rfc1123_date(Date) -> RFC1123Date

rfc1123_date/0 returns the current date in RFC 1123 format. rfc_date/1 converts the date in the Erlang format to the RFC 1123 date format.

Link to this function

split(String, RegExp, N)

View Source

split(String,RegExp,N) -> SplitRes

split/3 splits String in N chunks using RegExp. split/3 is equivalent to re:split/3 with the exception that N defines the maximum number of fields in FieldList.

split_path(RequestLine) -> {Path,QueryStringOrPathInfo}

split_path/1 splits RequestLine in a file reference (Path), and a QueryString or a PathInfo string as specified in RFC 2616. A QueryString is isolated from Path with a question mark (?) and PathInfo with a slash (/). In the case of a QueryString, everything before ? is a Path and everything after ? is a QueryString. In the case of a PathInfo, RequestLine is scanned from left-to-right on the hunt for longest possible Path being a file or a directory. Everything after the longest possible Path, isolated with a /, is regarded as PathInfo

split_script_path(RequestLine) -> Split

split_script_path/1 is equivalent to split_path/1 with one exception. If the longest possible path is not a regular, accessible, and executable file, then not_a_script is returned.