.TH httpd_util 3erl "inets 7.3.2" "Ericsson AB" "Erlang Module Definition" .SH NAME httpd_util \- Miscellaneous utility functions to be used when implementing Erlang web server API modules. .SH DESCRIPTION .LP This module provides the Erlang web server API module programmer with miscellaneous utility functions\&. .SH EXPORTS .LP .B convert_request_date(DateString) -> ErlDate|bad_date .br .RS .LP Types: .RS 3 DateString = string() .br ErlDate = calendar:datetime() .br .RE .RE .RS .LP \fIconvert_request_date/1\fR\& converts \fIDateString\fR\& to the Erlang date format\&. \fIDateString\fR\& must be in one of the three date formats defined in RFC 2616\&. .RE .LP .B create_etag(FileInfo) -> Etag .br .RS .LP Types: .RS 3 FileInfo = file_info() .br Etag = string() .br .RE .RE .RS .LP \fIcreate_etag/1\fR\& calculates the Etag for a file from its size and time for last modification\&. \fIFileInfo\fR\& is a record defined in \fIkernel/include/file\&.hrl\fR\&\&. .RE .LP .B day(NthDayOfWeek) -> DayOfWeek .br .RS .LP Types: .RS 3 NthDayOfWeek = 1-7 .br DayOfWeek = string() .br .RE .RE .RS .LP \fIday/1\fR\& converts the day of the week (\fINthDayOfWeek\fR\&) from an integer (1-7) to an abbreviated string, that is: .LP 1 = "Mon", 2 = "Tue", \&.\&.\&., 7 = "Sat"\&. .RE .LP .B decode_hex(HexValue) -> DecValue .br .RS .LP Types: .RS 3 HexValue = DecValue = string() .br .RE .RE .RS .LP Converts the hexadecimal value \fIHexValue\fR\& into its decimal equivalent (\fIDecValue\fR\&)\&. .RE .LP .B flatlength(NestedList) -> Size .br .RS .LP Types: .RS 3 NestedList = list() .br Size = integer() .br .RE .RE .RS .LP \fIflatlength/1\fR\& computes the size of the possibly nested list \fINestedList\fR\&, which can contain binaries\&. .RE .LP .B hexlist_to_integer(HexString) -> Number .br .RS .LP Types: .RS 3 Number = integer() .br HexString = string() .br .RE .RE .RS .LP \fIhexlist_to_integer\fR\& converts the hexadecimal value of \fIHexString\fR\& to an integer\&. .RE .LP .B integer_to_hexlist(Number) -> HexString .br .RS .LP Types: .RS 3 Number = integer() .br HexString = string() .br .RE .RE .RS .LP \fIinteger_to_hexlist/1\fR\& returns a string representing \fINumber\fR\& in a hexadecimal form\&. .RE .LP .B lookup(ETSTable,Key) -> Result .br .B lookup(ETSTable,Key,Undefined) -> Result .br .RS .LP Types: .RS 3 ETSTable = ets_table() .br Key = term() .br Result = term() | undefined | Undefined .br Undefined = term() .br .RE .RE .RS .LP \fIlookup\fR\& extracts \fI{Key,Value}\fR\& tuples from \fIETSTable\fR\& and returns the \fIValue\fR\& associated with \fIKey\fR\&\&. If \fIETSTable\fR\& is of type \fIbag\fR\&, only the first \fIValue\fR\& associated with \fIKey\fR\& is returned\&. \fIlookup/2\fR\& returns \fIundefined\fR\& and \fIlookup/3\fR\& returns \fIUndefined\fR\& if no \fIValue\fR\& is found\&. .RE .LP .B lookup_mime(ConfigDB,Suffix) .br .B lookup_mime(ConfigDB,Suffix,Undefined) -> MimeType .br .RS .LP Types: .RS 3 ConfigDB = ets_table() .br Suffix = string() .br MimeType = string() | undefined | Undefined .br Undefined = term() .br .RE .RE .RS .LP \fIlookup_mime\fR\& returns the MIME type associated with a specific file suffix as specified in the file \fImime\&.types\fR\& (located in the config directory)\&. .RE .LP .B lookup_mime_default(ConfigDB,Suffix) .br .B lookup_mime_default(ConfigDB,Suffix,Undefined) -> MimeType .br .RS .LP Types: .RS 3 ConfigDB = ets_table() .br Suffix = string() .br MimeType = string() | undefined | Undefined .br Undefined = term() .br .RE .RE .RS .LP \fIlookup_mime_default\fR\& returns the MIME type associated with a specific file suffix as specified in the \fImime\&.types\fR\& file (located in the config directory)\&. If no appropriate association is found, the value of \fIDefaultType\fR\& is returned\&. .RE .LP .B message(StatusCode,PhraseArgs,ConfigDB) -> Message .br .RS .LP Types: .RS 3 StatusCode = 301 | 400 | 403 | 404 | 500 | 501 | 504 .br PhraseArgs = term() .br ConfigDB = ets_table .br Message = string() .br .RE .RE .RS .LP \fImessage/3\fR\& returns an informative HTTP 1\&.1 status string in HTML\&. Each \fIStatusCode\fR\& requires a specific \fIPhraseArgs\fR\&: .RS 2 .TP 2 .B \fI301\fR\&: \fIstring()\fR\&: A URL pointing at the new document position\&. .TP 2 .B \fI400 | 401 | 500\fR\&: \fInone\fR\& (no \fIPhraseArgs\fR\&)\&. .TP 2 .B \fI403 | 404\fR\&: \fIstring()\fR\&: A \fIRequest-URI\fR\& as described in RFC 2616\&. .TP 2 .B \fI501\fR\&: \fI{Method,RequestURI,HTTPVersion}\fR\&: The HTTP \fIMethod\fR\&, \fIRequest-URI\fR\&, and \fIHTTP-Version\fR\& as defined in RFC 2616\&. .TP 2 .B \fI504\fR\&: \fIstring()\fR\&: A string describing why the service was unavailable\&. .RE .RE .LP .B month(NthMonth) -> Month .br .RS .LP Types: .RS 3 NthMonth = 1-12 .br Month = string() .br .RE .RE .RS .LP \fImonth/1\fR\& converts the month \fINthMonth\fR\& as an integer (1-12) to an abbreviated string, that is: .LP 1 = "Jan", 2 = "Feb", \&.\&.\&., 12 = "Dec"\&. .RE .LP .B multi_lookup(ETSTable,Key) -> Result .br .RS .LP Types: .RS 3 ETSTable = ets_table() .br Key = term() .br Result = [term()] .br .RE .RE .RS .LP \fImulti_lookup\fR\& extracts all \fI{Key,Value}\fR\& tuples from an \fIETSTable\fR\& and returns \fIall\fR\& \fIValues\fR\& associated with \fIKey\fR\& in a list\&. .RE .LP .B reason_phrase(StatusCode) -> Description .br .RS .LP Types: .RS 3 StatusCode = 100| 200 | 201 | 202 | 204 | 205 | 206 | 300 | 301 | 302 | 303 | 304 | 400 | 401 | 402 | 403 | 404 | 405 | 406 | 410 411 | 412 | 413 | 414 415 | 416 | 417 | 500 | 501 | 502 | 503 | 504 | 505 .br Description = string() .br .RE .RE .RS .LP \fIreason_phrase\fR\& returns \fIDescription\fR\& of an HTTP 1\&.1 \fIStatusCode\fR\&, for example, 200 is "OK" and 201 is "Created"\&. For more information, see RFC 2616\&. .RE .LP .B rfc1123_date() -> RFC1123Date .br .B rfc1123_date(Date) -> RFC1123Date .br .RS .LP Types: .RS 3 Date = calendar:datetime() .br RFC1123Date = string() .br .RE .RE .RS .LP \fIrfc1123_date/0\fR\& returns the current date in RFC 1123 format\&. \fIrfc_date/1\fR\& converts the date in the Erlang format to the RFC 1123 date format\&. .RE .LP .B split(String,RegExp,N) -> SplitRes .br .RS .LP Types: .RS 3 String = RegExp = string() .br SplitRes = {ok, FieldList} | {error, errordesc()} .br Fieldlist = [string()] .br N = integer .br .RE .RE .RS .LP \fIsplit/3\fR\& splits \fIString\fR\& in \fIN\fR\& chunks using \fIRegExp\fR\&\&. \fIsplit/3\fR\& is equivalent to \fIregexp:split/2\fR\& with the exception that \fIN\fR\& defines the maximum number of fields in \fIFieldList\fR\&\&. .RE .LP .B split_script_path(RequestLine) -> Splitted .br .RS .LP Types: .RS 3 RequestLine = string() .br Splitted = not_a_script | {Path, PathInfo, QueryString} .br Path = QueryString = PathInfo = string() .br .RE .RE .RS .LP \fIsplit_script_path/1\fR\& is equivalent to \fIsplit_path/1\fR\& with one exception\&. If the longest possible path is not a regular, accessible, and executable file, then \fInot_a_script\fR\& is returned\&. .RE .LP .B split_path(RequestLine) -> {Path,QueryStringOrPathInfo} .br .RS .LP Types: .RS 3 RequestLine = Path = QueryStringOrPathInfo = string() .br .RE .RE .RS .LP \fIsplit_path/1\fR\& splits \fIRequestLine\fR\& in a file reference (\fIPath\fR\&), and a \fIQueryString\fR\& or a \fIPathInfo\fR\& string as specified in RFC 2616\&. A \fIQueryString\fR\& is isolated from \fIPath\fR\& with a question mark (\fI?\fR\&) and \fIPathInfo\fR\& with a slash (/)\&. In the case of a \fIQueryString\fR\&, everything before \fI?\fR\& is a \fIPath\fR\& and everything after \fI?\fR\& is a \fIQueryString\fR\&\&. In the case of a \fIPathInfo\fR\&, \fIRequestLine\fR\& is scanned from left-to-right on the hunt for longest possible \fIPath\fR\& being a file or a directory\&. Everything after the longest possible \fIPath\fR\&, isolated with a \fI/\fR\&, is regarded as \fIPathInfo\fR\&\&. The resulting \fIPath\fR\& is decoded using \fIdecode_hex/1\fR\& before delivery\&. .RE .LP .B strip(String) -> Stripped .br .RS .LP Types: .RS 3 String = Stripped = string() .br .RE .RE .RS .LP \fIstrip/1\fR\& removes any leading or trailing linear white space from the string\&. Linear white space is to be read as horizontal tab or space\&. .RE .LP .B suffix(FileName) -> Suffix .br .RS .LP Types: .RS 3 FileName = Suffix = string() .br .RE .RE .RS .LP \fIsuffix/1\fR\& is equivalent to \fIfilename:extension/1\fR\& with the exception that \fISuffix\fR\& is returned without a leading dot (\fI\&.\fR\&)\&. .RE .SH "SEE ALSO" .LP httpd(3erl)