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