1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
|
<?xml version="1.0" encoding="iso-8859-1" ?>
<!DOCTYPE erlref SYSTEM "erlref.dtd">
<erlref>
<header>
<copyright>
<year>1997</year><year>2012</year>
<holder>Ericsson AB. All Rights Reserved.</holder>
</copyright>
<legalnotice>
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.
</legalnotice>
<title>httpd_util</title>
<prepared>Joakim Grebenö</prepared>
<docno></docno>
<date>1997-10-14</date>
<rev>2.2</rev>
<file>httpd_util.sgml</file>
</header>
<module>httpd_util</module>
<modulesummary>Miscellaneous utility functions to be used when implementing Erlang Web server API modules.</modulesummary>
<description>
<p>This module provides the Erlang Web Server API module
programmer with miscellaneous utility functions.</p>
<marker id="convert_request_date"></marker>
</description>
<funcs>
<func>
<name>convert_request_date(DateString) -> ErlDate|bad_date</name>
<fsummary>Convert The the date to the Erlang date format.</fsummary>
<type>
<v>DateString = string()</v>
<v>ErlDate = {{Year,Month,Date},{Hour,Min,Sec}}</v>
<v>Year = Month = Date = Hour = Min = Sec = integer()</v>
</type>
<desc>
<p><c>convert_request_date/1</c> converts <c>DateString</c> to
the Erlang date format. DateString must be in one of the three
date formats that is defined in the RFC 2616.</p>
<marker id="create_etag"></marker>
</desc>
</func>
<func>
<name>create_etag(FileInfo) -> Etag</name>
<fsummary>Calculates the Etag for a file.</fsummary>
<type>
<v>FileInfo = file_info()</v>
<v>Etag = string()</v>
</type>
<desc>
<p><c>create_etag/1</c> calculates the Etag for a file, from its
size and time for last modification. fileinfo is a record defined
in <c>kernel/include/file.hrl</c></p>
<marker id="decode_hex"></marker>
</desc>
</func>
<func>
<name>decode_hex(HexValue) -> DecValue</name>
<fsummary>Convert a hex value into its decimal equivalent.</fsummary>
<type>
<v>HexValue = DecValue = string()</v>
</type>
<desc>
<p>Converts the hexadecimal value <c>HexValue</c> into its
decimal equivalent (<c>DecValue</c>).</p>
<marker id="day"></marker>
</desc>
</func>
<func>
<name>day(NthDayOfWeek) -> DayOfWeek</name>
<fsummary>Convert the day of the week (integer [1-7]) to an abbreviated string.</fsummary>
<type>
<v>NthDayOfWeek = 1-7</v>
<v>DayOfWeek = string()</v>
</type>
<desc>
<marker id="day"></marker>
<p><c>day/1</c> converts the day of the week
(<c>NthDayOfWeek</c>) as an integer (1-7) to an abbreviated
string, that is: </p>
<p>1 = "Mon", 2 = "Tue", ..., 7 = "Sat".</p>
<marker id="flatlength"></marker>
</desc>
</func>
<func>
<name>flatlength(NestedList) -> Size</name>
<fsummary>Compute the size of a possibly nested list.</fsummary>
<type>
<v>NestedList = list()</v>
<v>Size = integer()</v>
</type>
<desc>
<marker id="flatlength"></marker>
<p><c>flatlength/1</c> computes the size of the possibly nested
list <c>NestedList</c>. Which may contain binaries.</p>
<marker id="hexlist_to_integer"></marker>
</desc>
</func>
<!--
<func>
<name>header(StatusCode,PersistentConn)</name>
<name>header(StatusCode,Date)</name>
<name>header(StatusCode,MimeType,Date)</name>
<name>header(StatusCode,MimeType,PersistentConn,Date) -> HTTPHeader</name>
<fsummary>Generate a HTTP 1.1 header.</fsummary>
<type>
<v>StatusCode = integer()</v>
<v>Date = rfc1123_date()</v>
<v>MimeType = string()</v>
<v>PersistentConn = true | false</v>
</type>
<desc>
<marker id="header"></marker>
<p><c>header</c> returns a HTTP 1.1 header string. The
<c>StatusCode</c> is one of the status codes defined in RFC
2616 and the <c>Date</c> string is RFC 1123
compliant. (See <seealso marker="#rfc1123_date">rfc1123_date/0</seealso>).
</p>
<p>Note that the two version of <c>header/n</c> that does not
has a <c>PersistentConn</c> argument is there only for
backward compatibility, and must not be used in new Erlang
Webserver API modules. that will support persistent
connections.</p>
<marker id="hexlist_to_integer"></marker>
</desc>
</func>
-->
<func>
<name>hexlist_to_integer(HexString) -> Number</name>
<fsummary>Convert a hexadecimal string to an integer.</fsummary>
<type>
<v>Number = integer()</v>
<v>HexString = string()</v>
</type>
<desc>
<p><c>hexlist_to_integer</c> Convert the Hexadecimal value of
HexString to an integer.</p>
<marker id="integer_to_hexlist"></marker>
</desc>
</func>
<func>
<name>integer_to_hexlist(Number) -> HexString</name>
<fsummary>Convert an integer to a hexadecimal string.</fsummary>
<type>
<v>Number = integer()</v>
<v>HexString = string()</v>
</type>
<desc>
<marker id="integer_to_hexlist"></marker>
<p><c>integer_to_hexlist/1</c> Returns a string that represents
the Number in a Hexadecimal form.</p>
<marker id="lookup"></marker>
</desc>
</func>
<func>
<name>lookup(ETSTable,Key) -> Result</name>
<name>lookup(ETSTable,Key,Undefined) -> Result</name>
<fsummary>Extract the first value associated with a key in an ETS table.</fsummary>
<type>
<v>ETSTable = ets_table()</v>
<v>Key = term()</v>
<v>Result = term() | undefined | Undefined</v>
<v>Undefined = term()</v>
</type>
<desc>
<p><c>lookup</c> extracts <c>{Key,Value}</c> tuples from
<c>ETSTable</c> and returns the <c>Value</c> associated
with <c>Key</c>. If <c>ETSTable</c> is of type <c>bag</c>
only the first <c>Value</c> associated with <c>Key</c> is
returned. <c>lookup/2</c> returns <c>undefined</c> and
<c>lookup/3</c> returns <c>Undefined</c> if no <c>Value</c>
is found.</p>
<marker id="lookup_mime"></marker>
</desc>
</func>
<func>
<name>lookup_mime(ConfigDB,Suffix)</name>
<name>lookup_mime(ConfigDB,Suffix,Undefined) -> MimeType</name>
<fsummary>Return the mime type associated with a specific file suffix. </fsummary>
<type>
<v>ConfigDB = ets_table()</v>
<v>Suffix = string()</v>
<v>MimeType = string() | undefined | Undefined</v>
<v>Undefined = term()</v>
</type>
<desc>
<marker id="lookup_mime"></marker>
<p><c>lookup_mime</c> returns the mime type associated with a
specific file suffix as specified in the <c>mime.types</c>
file (located in the
<path unix="$SERVER_ROOT/conf/mime.types" windows="%SERVER_ROOT%\conf\mime.types">config directory</path>).</p>
<marker id="lookup_mime_default"></marker>
</desc>
</func>
<func>
<name>lookup_mime_default(ConfigDB,Suffix)</name>
<name>lookup_mime_default(ConfigDB,Suffix,Undefined) -> MimeType</name>
<fsummary>Return the mime type associated with a specific file suffix or the value of the DefaultType.</fsummary>
<type>
<v>ConfigDB = ets_table()</v>
<v>Suffix = string()</v>
<v>MimeType = string() | undefined | Undefined</v>
<v>Undefined = term()</v>
</type>
<desc>
<marker id="lookup_mime_default"></marker>
<p><c>lookup_mime_default</c> returns the mime type associated
with a specific file suffix as specified in the
<c>mime.types</c> file (located in the
<path unix="$SERVER_ROOT/conf/mime.types" windows="%SERVER_ROOT%\conf\mime.types">config directory</path>).
If no appropriate association can be found
the value of DefaultType is
returned.</p>
<marker id="message"></marker>
</desc>
</func>
<func>
<name>message(StatusCode,PhraseArgs,ConfigDB) -> Message</name>
<fsummary>Return an informative HTTP 1.1 status string in HTML.</fsummary>
<type>
<v>StatusCode = 301 | 400 | 403 | 404 | 500 | 501 | 504</v>
<v>PhraseArgs = term()</v>
<v>ConfigDB = ets_table</v>
<v>Message = string()</v>
</type>
<desc>
<marker id="message"></marker>
<p><c>message/3</c> returns an informative HTTP 1.1 status
string in HTML. Each <c>StatusCode</c> requires a specific
<c>PhraseArgs</c>:
</p>
<taglist>
<tag><c>301</c></tag>
<item><c>string()</c>: A URL pointing at the new document
position.</item>
<tag><c>400 | 401 | 500</c></tag>
<item><c>none</c> (No <c>PhraseArgs</c>)</item>
<tag><c>403 | 404</c></tag>
<item><c>string()</c>: A <c>Request-URI</c> as described in
RFC 2616.</item>
<tag><c>501</c></tag>
<item><c>{Method,RequestURI,HTTPVersion}</c>: The HTTP
<c>Method</c>, <c>Request-URI</c> and <c>HTTP-Version</c>
as defined in RFC 2616.</item>
<tag><c>504</c></tag>
<item><c>string()</c>: A string describing why the service
was unavailable.</item>
</taglist>
<marker id="month"></marker>
</desc>
</func>
<func>
<name>month(NthMonth) -> Month</name>
<fsummary>Convert the month as an integer (1-12) to an abbreviated string.</fsummary>
<type>
<v>NthMonth = 1-12</v>
<v>Month = string()</v>
</type>
<desc>
<marker id="month"></marker>
<p><c>month/1</c> converts the month <c>NthMonth</c> as an
integer (1-12) to an abbreviated string, that is: </p>
<p>1 = "Jan", 2 = "Feb", ..., 12 = "Dec".</p>
<marker id="multi_lookup"></marker>
</desc>
</func>
<func>
<name>multi_lookup(ETSTable,Key) -> Result</name>
<fsummary>Extract the values associated with a key in a ETS table.</fsummary>
<type>
<v>ETSTable = ets_table()</v>
<v>Key = term()</v>
<v>Result = [term()]</v>
</type>
<desc>
<p><c>multi_lookup</c> extracts all <c>{Key,Value}</c> tuples
from an <c>ETSTable</c> and returns <em>all</em><c>Values</c> associated with the <c>Key</c> in a list.</p>
<marker id="reason phrase"></marker>
</desc>
</func>
<func>
<name>reason_phrase(StatusCode) -> Description</name>
<fsummary>Return the description of an HTTP 1.1 status code.</fsummary>
<type>
<v>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</v>
<v>Description = string()</v>
</type>
<desc>
<p><c>reason_phrase</c> returns the <c>Description</c> of an
HTTP 1.1 <c>StatusCode</c>, for example 200 is "OK" and 201
is "Created". Read RFC 2616 for further information.</p>
<marker id="rfc1123_date"></marker>
</desc>
</func>
<func>
<name>rfc1123_date() -> RFC1123Date</name>
<name>rfc1123_date({{YYYY,MM,DD},{Hour,Min,Sec}}) -> RFC1123Date</name>
<fsummary>Return the current date in RFC 1123 format.</fsummary>
<type>
<v>YYYY = MM = DD = Hour = Min = Sec = integer()</v>
<v>RFC1123Date = string()</v>
</type>
<desc>
<marker id="rfc1123_date"></marker>
<p><c>rfc1123_date/0</c> returns the current date in RFC 1123
format. <c>rfc_date/1</c> converts the date in the Erlang format
to the RFC 1123 date format.</p>
<marker id="split"></marker>
</desc>
</func>
<func>
<name>split(String,RegExp,N) -> SplitRes</name>
<fsummary>Split a string in N chunks using a regular expression.</fsummary>
<type>
<v>String = RegExp = string()</v>
<v>SplitRes = {ok, FieldList} | {error, errordesc()}</v>
<v>Fieldlist = [string()]</v>
<v>N = integer</v>
</type>
<desc>
<marker id="split"></marker>
<p><c>split/3</c> splits the <c>String</c> in <c>N</c> chunks
using the <c>RegExp</c>. <c>split/3</c> is is equivalent to
<c>regexp:split/2</c> with one exception, that is <c>N</c>
defines the number of maximum number of fields in the
<c>FieldList</c>.</p>
<marker id="split_script_path"></marker>
</desc>
</func>
<func>
<name>split_script_path(RequestLine) -> Splitted</name>
<fsummary>Split a <c>RequestLine</c>in a file reference to an executable and a<c>QueryString</c>or a <c>PathInfo</c>string.</fsummary>
<type>
<v>RequestLine = string()</v>
<v>Splitted = not_a_script | {Path, PathInfo, QueryString}</v>
<v>Path = QueryString = PathInfo = string()</v>
</type>
<desc>
<marker id="split_script_path"></marker>
<p><c>split_script_path/1</c> is equivalent to
<c>split_path/1</c> with one exception. If the longest
possible path is not a regular, accessible and executable
file <c>not_a_script</c> is returned.</p>
<marker id="split_path"></marker>
</desc>
</func>
<func>
<name>split_path(RequestLine) -> {Path,QueryStringOrPathInfo}</name>
<fsummary>Split a <c>RequestLine</c>in a file reference and a <c>QueryString</c>or a<c>PathInfo</c>string.</fsummary>
<type>
<v>RequestLine = Path = QueryStringOrPathInfo = string()</v>
</type>
<desc>
<marker id="split_path"></marker>
<p><c>split_path/1</c> splits the <c>RequestLine</c> in a file
reference (<c>Path</c>) and a <c>QueryString</c> or a
<c>PathInfo</c> string as specified in RFC 2616. A
<c>QueryString</c> is isolated from the <c>Path</c> with a
question mark (<c>?</c>) and <c>PathInfo</c> with a slash
(/). In the case of a <c>QueryString</c>, everything before
the <c>?</c> is a <c>Path</c> and everything after a
<c>QueryString</c>. In the case of a <c>PathInfo</c> the
<c>RequestLine</c> is scanned from left-to-right on the hunt
for longest possible <c>Path</c> being a file or a
directory. Everything after the longest possible
<c>Path</c>, isolated with a <c>/</c>, is regarded as
<c>PathInfo</c>. The resulting <c>Path</c> is decoded using
<c>decode_hex/1</c> before delivery.</p>
<marker id="strip"></marker>
</desc>
</func>
<func>
<name>strip(String) -> Stripped</name>
<fsummary>Returns String where the leading and trailing space and tabs has been removed.</fsummary>
<type>
<v>String = Stripped = string()</v>
</type>
<desc>
<marker id="strip"></marker>
<p><c>strip/1</c> removes any leading or trailing linear white
space from the string. Linear white space should be read as
horizontal tab or space.</p>
<marker id="suffix"></marker>
</desc>
</func>
<func>
<name>suffix(FileName) -> Suffix</name>
<fsummary>Extract the file suffix from a given filename.</fsummary>
<type>
<v>FileName = Suffix = string()</v>
</type>
<desc>
<marker id="suffix"></marker>
<p><c>suffix/1</c> is equivalent to
<c>filename:extension/1</c> with one exception, that is
<c>Suffix</c> is returned without a leading dot (<c>.</c>). </p>
</desc>
</func>
</funcs>
<section>
<marker id="see_also"></marker>
<title>SEE ALSO</title>
<p><seealso marker="httpd">httpd(3)</seealso></p>
</section>
</erlref>
|