19972010Ericsson AB. All Rights Reserved.
The contents of this file are subject to the Erlang Public License,
Version 1.1, (the "License"); you may not use this file except in
compliance with the License. You should have received a copy of the
Erlang Public License along with this software. If not, it can be
retrieved online at http://www.erlang.org/.
Software distributed under the License is distributed on an "AS IS"
basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
the License for the specific language governing rights and limitations
under the License.
httpd_utilJoakim Grebenö1997-10-142.2httpd_util.sgmlhttpd_utilMiscellaneous 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.
convert_request_date(DateString) -> ErlDate|bad_dateConvert The the date to the Erlang date format.DateString = string()ErlDate = {{Year,Month,Date},{Hour,Min,Sec}}Year = Month = Date = Hour = Min = Sec = integer()
convert_request_date/1 converts DateString to
the Erlang date format. DateString must be in one of the three
date formats that is defined in the RFC 2616.
create_etag(FileInfo) -> EtagCalculates the Etag for a file.FileInfo = file_info()Etag = string()
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
decode_hex(HexValue) -> DecValueConvert a hex value into its decimal equivalent.HexValue = DecValue = string()
Converts the hexadecimal value HexValue into its
decimal equivalent (DecValue).
day(NthDayOfWeek) -> DayOfWeekConvert the day of the week (integer [1-7]) to an abbreviated string.NthDayOfWeek = 1-7DayOfWeek = string()
day/1 converts the day of the week
(NthDayOfWeek) as an integer (1-7) to an abbreviated
string, that is:
1 = "Mon", 2 = "Tue", ..., 7 = "Sat".
flatlength(NestedList) -> SizeCompute the size of a possibly nested list.NestedList = list()Size = integer()
flatlength/1 computes the size of the possibly nested
list NestedList. Which may contain binaries.
hexlist_to_integer(HexString) -> NumberConvert a hexadecimal string to an integer.Number = integer()HexString = string()
hexlist_to_integer Convert the Hexadecimal value of
HexString to an integer.
integer_to_hexlist(Number) -> HexStringConvert an integer to a hexadecimal string.Number = integer()HexString = string()
integer_to_hexlist/1 Returns a string that represents
the Number in a Hexadecimal form.
lookup(ETSTable,Key) -> Resultlookup(ETSTable,Key,Undefined) -> ResultExtract the first value associated with a key in an ETS table.ETSTable = ets_table()Key = term()Result = term() | undefined | UndefinedUndefined = term()
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.
lookup_mime(ConfigDB,Suffix)lookup_mime(ConfigDB,Suffix,Undefined) -> MimeTypeReturn the mime type associated with a specific file suffix. ConfigDB = ets_table()Suffix = string()MimeType = string() | undefined | UndefinedUndefined = term()
lookup_mime returns the mime type associated with a
specific file suffix as specified in the mime.types
file (located in the
config directory).
lookup_mime_default(ConfigDB,Suffix)lookup_mime_default(ConfigDB,Suffix,Undefined) -> MimeTypeReturn the mime type associated with a specific file suffix or the value of the DefaultType.ConfigDB = ets_table()Suffix = string()MimeType = string() | undefined | UndefinedUndefined = term()
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 can be found
the value of DefaultType is
returned.
message/3 returns an informative HTTP 1.1 status
string in HTML. Each StatusCode requires a specific
PhraseArgs:
301string(): A URL pointing at the new document
position.400 | 401 | 500none (No PhraseArgs)403 | 404string(): 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.504string(): A string describing why the service
was unavailable.month(NthMonth) -> MonthConvert the month as an integer (1-12) to an abbreviated string.NthMonth = 1-12Month = string()
month/1 converts the month NthMonth as an
integer (1-12) to an abbreviated string, that is:
1 = "Jan", 2 = "Feb", ..., 12 = "Dec".
multi_lookup(ETSTable,Key) -> ResultExtract the values associated with a key in a ETS table.ETSTable = ets_table()Key = term()Result = [term()]
multi_lookup extracts all {Key,Value} tuples
from an ETSTable and returns allValues associated with the Key in a list.
reason_phrase returns the Description of an
HTTP 1.1 StatusCode, for example 200 is "OK" and 201
is "Created". Read RFC 2616 for further information.
rfc1123_date() -> RFC1123Daterfc1123_date({{YYYY,MM,DD},{Hour,Min,Sec}}}) -> RFC1123DateReturn the current date in RFC 1123 format.YYYY = MM = DD = Hour = Min =Sec = integer()RFC1123Date = string()
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.
split(String,RegExp,N) -> SplitResSplit a string in N chunks using a regular expression.String = RegExp = string()SplitRes = {ok, FieldList} | {error, errordesc()}Fieldlist = [string()]N = integer
split/3 splits the String in N chunks
using the RegExp. split/3 is is equivalent to
regexp:split/2 with one exception, that is N
defines the number of maximum number of fields in the
FieldList.
split_script_path(RequestLine) -> SplittedSplit a RequestLinein a file reference to an executable and aQueryStringor a PathInfostring.RequestLine = string()Splitted = not_a_script | {Path, PathInfo, QueryString}Path = QueryString = PathInfo = string()
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 not_a_script is returned.
split_path(RequestLine) -> {Path,QueryStringOrPathInfo}Split a RequestLinein a file reference and a QueryStringor aPathInfostring.RequestLine = Path = QueryStringOrPathInfo = string()
split_path/1 splits the RequestLine in a file
reference (Path) and a QueryString or a
PathInfo string as specified in RFC 2616. A
QueryString is isolated from the Path with a
question mark (?) and PathInfo with a slash
(/). In the case of a QueryString, everything before
the ? is a Path and everything after a
QueryString. In the case of a PathInfo the
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. The resulting Path is decoded using
decode_hex/1 before delivery.
strip(String) -> StrippedReturns String where the leading and trailing space and tabs has been removed.String = Stripped = string()
strip/1 removes any leading or trailing linear white
space from the string. Linear white space should be read as
horizontal tab or space.
suffix(FileName) -> SuffixExtract the file suffix from a given filename.FileName = Suffix = string()
suffix/1 is equivalent to
filename:extension/1 with one exception, that is
Suffix is returned without a leading dot (.).