1httpd_util(3) Erlang Module Definition httpd_util(3)
2
3
4
6 httpd_util - Miscellaneous utility functions to be used when implement‐
7 ing
8 Erlang web server API modules.
9
11 This module provides the Erlang web server API module programmer with
12 miscellaneous utility functions.
13
14 Note:
15 Note the module is only recommended for using with httpd - for other
16 cases it should be considered as deprecated.
17
18
20 convert_request_date(DateString) -> ErlDate|bad_date
21
22 Types:
23
24 DateString = string()
25 ErlDate = calendar:datetime()
26
27 convert_request_date/1 converts DateString to the Erlang date
28 format. DateString must be in one of the three date formats de‐
29 fined in RFC 2616.
30
31 create_etag(FileInfo) -> Etag
32
33 Types:
34
35 FileInfo = file_info()
36 Etag = string()
37
38 create_etag/1 calculates the Etag for a file from its size and
39 time for last modification. FileInfo is a record defined in ker‐
40 nel/include/file.hrl.
41
42 day(NthDayOfWeek) -> DayOfWeek
43
44 Types:
45
46 NthDayOfWeek = 1-7
47 DayOfWeek = string()
48
49 day/1 converts the day of the week (NthDayOfWeek) from an inte‐
50 ger (1-7) to an abbreviated string, that is:
51
52 1 = "Mon", 2 = "Tue", ..., 7 = "Sat".
53
54 decode_hex(HexValue) -> DecValue
55
56 Types:
57
58 HexValue = DecValue = string()
59
60 Converts the hexadecimal value HexValue into its decimal equiva‐
61 lent (DecValue).
62
63 flatlength(NestedList) -> Size
64
65 Types:
66
67 NestedList = list()
68 Size = integer()
69
70 flatlength/1 computes the size of the possibly nested list Nest‐
71 edList, which can contain binaries.
72
73 hexlist_to_integer(HexString) -> Number
74
75 Types:
76
77 Number = integer()
78 HexString = string()
79
80 hexlist_to_integer converts the hexadecimal value of HexString
81 to an integer.
82
83 integer_to_hexlist(Number) -> HexString
84
85 Types:
86
87 Number = integer()
88 HexString = string()
89
90 integer_to_hexlist/1 returns a string representing Number in a
91 hexadecimal form.
92
93 lookup(ETSTable,Key) -> Result
94 lookup(ETSTable,Key,Undefined) -> Result
95
96 Types:
97
98 ETSTable = ets_table()
99 Key = term()
100 Result = term() | undefined | Undefined
101 Undefined = term()
102
103 lookup extracts {Key,Value} tuples from ETSTable and returns the
104 Value associated with Key. If ETSTable is of type bag, only the
105 first Value associated with Key is returned. lookup/2 returns
106 undefined and lookup/3 returns Undefined if no Value is found.
107
108 lookup_mime(ConfigDB,Suffix)
109 lookup_mime(ConfigDB,Suffix,Undefined) -> MimeType
110
111 Types:
112
113 ConfigDB = ets_table()
114 Suffix = string()
115 MimeType = string() | undefined | Undefined
116 Undefined = term()
117
118 lookup_mime returns the MIME type associated with a specific
119 file suffix as specified in the file mime.types (located in the
120 config directory).
121
122 lookup_mime_default(ConfigDB,Suffix)
123 lookup_mime_default(ConfigDB,Suffix,Undefined) -> MimeType
124
125 Types:
126
127 ConfigDB = ets_table()
128 Suffix = string()
129 MimeType = string() | undefined | Undefined
130 Undefined = term()
131
132 lookup_mime_default returns the MIME type associated with a spe‐
133 cific file suffix as specified in the mime.types file (located
134 in the config directory). If no appropriate association is
135 found, the value of DefaultType is returned.
136
137 message(StatusCode,PhraseArgs,ConfigDB) -> Message
138
139 Types:
140
141 StatusCode = 301 | 400 | 403 | 404 | 500 | 501 | 504
142 PhraseArgs = term()
143 ConfigDB = ets_table
144 Message = string()
145
146 message/3 returns an informative HTTP 1.1 status string in HTML.
147 Each StatusCode requires a specific PhraseArgs:
148
149 301:
150 string(): A URL pointing at the new document position.
151
152 400 | 401 | 500:
153 none (no PhraseArgs).
154
155 403 | 404:
156 string(): A Request-URI as described in RFC 2616.
157
158 501:
159 {Method,RequestURI,HTTPVersion}: The HTTP Method, Request-
160 URI, and HTTP-Version as defined in RFC 2616.
161
162 504:
163 string(): A string describing why the service was unavail‐
164 able.
165
166 month(NthMonth) -> Month
167
168 Types:
169
170 NthMonth = 1-12
171 Month = string()
172
173 month/1 converts the month NthMonth as an integer (1-12) to an
174 abbreviated string, that is:
175
176 1 = "Jan", 2 = "Feb", ..., 12 = "Dec".
177
178 multi_lookup(ETSTable,Key) -> Result
179
180 Types:
181
182 ETSTable = ets_table()
183 Key = term()
184 Result = [term()]
185
186 multi_lookup extracts all {Key,Value} tuples from an ETSTable
187 and returns all Values associated with Key in a list.
188
189 reason_phrase(StatusCode) -> Description
190
191 Types:
192
193 StatusCode = 100 | 200 | 201 | 202 | 204 | 205 | 206 | 300 |
194 301 | 302 | 303 | 304 | 308 | 400 | 401 | 402 | 403 | 404 |
195 405 | 406 | 410 | 411 | 412 | 413 | 414 | 415 | 416 | 417 |
196 500 | 501 | 502 | 503 | 504 | 505
197 Description = string()
198
199 reason_phrase returns Description of an HTTP 1.1 StatusCode, for
200 example, 200 is "OK" and 201 is "Created". For more information,
201 see RFC 2616.
202
203 rfc1123_date() -> RFC1123Date
204 rfc1123_date(Date) -> RFC1123Date
205
206 Types:
207
208 Date = calendar:datetime()
209 RFC1123Date = string()
210
211 rfc1123_date/0 returns the current date in RFC 1123 format.
212 rfc_date/1 converts the date in the Erlang format to the RFC
213 1123 date format.
214
215 split(String,RegExp,N) -> SplitRes
216
217 Types:
218
219 String = RegExp = string()
220 SplitRes = {ok, FieldList} | {error, errordesc()}
221 Fieldlist = [string()]
222 N = integer
223
224 split/3 splits String in N chunks using RegExp. split/3 is
225 equivalent to regexp:split/2 with the exception that N defines
226 the maximum number of fields in FieldList.
227
228 split_script_path(RequestLine) -> Split
229
230 Types:
231
232 RequestLine = string()
233 Split = not_a_script | {Path, PathInfo, QueryString}
234 Path = QueryString = PathInfo = string()
235
236 split_script_path/1 is equivalent to split_path/1 with one ex‐
237 ception. If the longest possible path is not a regular, accessi‐
238 ble, and executable file, then not_a_script is returned.
239
240 split_path(RequestLine) -> {Path,QueryStringOrPathInfo}
241
242 Types:
243
244 RequestLine = Path = QueryStringOrPathInfo = string()
245
246 split_path/1 splits RequestLine in a file reference (Path), and
247 a QueryString or a PathInfo string as specified in RFC 2616. A
248 QueryString is isolated from Path with a question mark (?) and
249 PathInfo with a slash (/). In the case of a QueryString, every‐
250 thing before ? is a Path and everything after ? is a QueryS‐
251 tring. In the case of a PathInfo, RequestLine is scanned from
252 left-to-right on the hunt for longest possible Path being a file
253 or a directory. Everything after the longest possible Path, iso‐
254 lated with a /, is regarded as PathInfo. The resulting Path is
255 decoded using decode_hex/1 before delivery.
256
257 strip(String) -> Stripped
258
259 Types:
260
261 String = Stripped = string()
262
263 strip/1 removes any leading or trailing linear white space from
264 the string. Linear white space is to be read as horizontal tab
265 or space.
266
267 suffix(FileName) -> Suffix
268
269 Types:
270
271 FileName = Suffix = string()
272
273 suffix/1 is equivalent to filename:extension/1 with the excep‐
274 tion that Suffix is returned without a leading dot (.).
275
277 httpd(3)
278
279
280
281Ericsson AB inets 8.2.1 httpd_util(3)