檢視原始碼 httpd_util (inets v9.3.1)

實作 Erlang 網頁伺服器 API 模組時使用的雜項工具函式。

此模組為 Erlang 網頁伺服器 API 模組程式設計師提供雜項工具函式。

注意

請注意,此模組僅建議與 httpd 一起使用 - 對於其他情況,應視為已棄用。

另請參閱

httpd

摘要

函式

convert_request_date/1DateString 轉換為 Erlang 日期格式。DateString 必須是 RFC 2616 中定義的三種日期格式之一。

create_etag/1 從檔案大小和上次修改時間計算檔案的 Etag。FileInfo 是在 kernel/include/file.hrl 中定義的記錄。

day/1 將星期幾 (NthDayOfWeek) 從整數 (1-7) 轉換為縮寫字串,即

lookupETSTable 中提取 {Key, Value} 元組,並返回與 Key 關聯的 Value。如果 ETSTable 的類型為 bag,則僅返回與 Key 關聯的第一個 Valuelookup/2 返回 undefined,如果未找到 Value,則 lookup/3 返回 Undefined

lookup_mime 返回與檔案 mime.types(位於 config 目錄中)中指定的特定檔案後綴相關聯的 MIME 類型。

lookup_mime_default 返回與 mime.types 檔案(位於 config 目錄中)中指定的特定檔案後綴相關聯的 MIME 類型。如果找不到適當的關聯,則返回 DefaultType 的值。

message/3 以 HTML 格式返回資訊豐富的 HTTP 1.1 狀態字串。每個 StatusCode 都需要特定的 PhraseArgs

month/1 將月份 NthMonth 作為整數 (1-12) 轉換為縮寫字串,即

multi_lookupETSTable 中提取所有 {Key, Value} 元組,並在列表中返回與 Key 關聯的所有 Values

reason_phrase 返回 HTTP 1.1 StatusCodeDescription,例如,200 是 "OK",201 是 "Created"。如需更多資訊,請參閱 RFC 2616

rfc1123_date/0 以 RFC 1123 格式返回當前日期。rfc_date/1 將 Erlang 格式的日期轉換為 RFC 1123 日期格式。

split/3 使用 RegExpString 分割為 N 個區塊。split/3 等同於 re:split/3,但 N 定義了 FieldList 中欄位的最大數目。

split_path/1RequestLine 分割為檔案參考 (Path) 以及 RFC 2616 中指定的 QueryStringPathInfo 字串。QueryString 以問號 (?) 與 Path 隔離,而 PathInfo 以斜線 (/) 隔離。在 QueryString 的情況下,? 之前的所有內容都是 Path,而 ? 之後的所有內容都是 QueryString。在 PathInfo 的情況下,從左到右掃描 RequestLine,以尋找最長的可能 Path,該 Path 為檔案或目錄。最長可能 Path 之後的所有內容,以 / 隔離,都視為 PathInfo

split_script_path/1 等同於 split_path/1,但有一個例外。如果最長可能的路徑不是常規、可存取且可執行的檔案,則返回 not_a_script

函式

此函式的連結

convert_request_date(DateString)

檢視原始碼
-spec convert_request_date(DateString) -> ErlDate | bad_date
                              when DateString :: string(), ErlDate :: calendar:datetime().

convert_request_date/1DateString 轉換為 Erlang 日期格式。DateString 必須是 RFC 2616 中定義的三種日期格式之一。

-spec create_etag(FileInfo) -> Etag when FileInfo :: file:file_info(), Etag :: string().

create_etag/1 從檔案大小和上次修改時間計算檔案的 Etag。FileInfo 是在 kernel/include/file.hrl 中定義的記錄。

-spec day(NthDayOfWeek) -> DayOfWeek when NthDayOfWeek :: 1..7, DayOfWeek :: string().

day/1 將星期幾 (NthDayOfWeek) 從整數 (1-7) 轉換為縮寫字串,即

1 = "Mon",2 = "Tue",...,7 = "Sat"。

-spec lookup(EtsTable, Key) -> Result
                when EtsTable :: ets:table(), Key :: term(), Result :: term() | undefined.

等同於 lookup/3

此函式的連結

lookup(EtsTable, Key, Undefined)

檢視原始碼
-spec lookup(EtsTable, Key, Undefined) -> Result
                when
                    EtsTable :: ets:table(),
                    Key :: term(),
                    Undefined :: term(),
                    Result :: term() | Undefined.

lookupETSTable 中提取 {Key, Value} 元組,並返回與 Key 關聯的 Value。如果 ETSTable 的類型為 bag,則僅返回與 Key 關聯的第一個 Valuelookup/2 返回 undefined,如果未找到 Value,則 lookup/3 返回 Undefined

此函式的連結

lookup_mime(ConfigDB, Suffix)

檢視原始碼
-spec lookup_mime(ConfigDB, Suffix) -> MimeType
                     when ConfigDB :: ets:tid(), Suffix :: string(), MimeType :: string() | undefined.

等同於 lookup_mime/3

此函式的連結

lookup_mime(ConfigDB, Suffix, Undefined)

檢視原始碼
-spec lookup_mime(ConfigDB, Suffix, Undefined) -> MimeType
                     when
                         ConfigDB :: ets:tid(),
                         Suffix :: string(),
                         Undefined :: term(),
                         MimeType :: string() | Undefined.

lookup_mime 返回與檔案 mime.types(位於 config 目錄中)中指定的特定檔案後綴相關聯的 MIME 類型。

此函式的連結

lookup_mime_default(ConfigDB, Suffix)

檢視原始碼
-spec lookup_mime_default(ConfigDB, Suffix) -> MimeType
                             when
                                 ConfigDB :: ets:tid(),
                                 Suffix :: string(),
                                 MimeType :: string() | undefined.

等同於 lookup_mime_default/3

此函式的連結

lookup_mime_default(ConfigDB, Suffix, Undefined)

檢視原始碼
-spec lookup_mime_default(ConfigDB, Suffix, Undefined) -> MimeType
                             when
                                 ConfigDB :: ets:tid(),
                                 Suffix :: string(),
                                 Undefined :: term(),
                                 MimeType :: string() | Undefined.

lookup_mime_default 返回與 mime.types 檔案(位於 config 目錄中)中指定的特定檔案後綴相關聯的 MIME 類型。如果找不到適當的關聯,則返回 DefaultType 的值。

此函式的連結

message(StatusCode, PhraseArgs, ConfigDB)

檢視原始碼
-spec message(StatusCode, PhraseArgs, ConfigDB) -> Message
                 when
                     StatusCode ::
                         301 | 304 | 400 | 401 | 403 | 404 | 408 | 412 | 413 | 414 | 500 | 501 | 503 |
                         504,
                     PhraseArgs :: term(),
                     ConfigDB :: ets:tid(),
                     Message :: string().

message/3 以 HTML 格式返回資訊豐富的 HTTP 1.1 狀態字串。每個 StatusCode 都需要特定的 PhraseArgs

  • 301 - string/0:指向新文件位置的 URL。

  • 400 | 401 | 500 - none(沒有 PhraseArgs)。

  • 403 | 404 - string/0RFC 2616 中描述的 Request-URI

  • 501 - {Method, RequestURI, HTTPVersion}:RFC 2616 中定義的 HTTP MethodRequest-URIHTTP-Version

  • 504 - string/0:描述服務為何無法使用的字串。

-spec month(NthMonth) -> Month when NthMonth :: 1..12, Month :: string().

month/1 將月份 NthMonth 作為整數 (1-12) 轉換為縮寫字串,即

1 = "Jan",2 = "Feb",...,12 = "Dec"。

此函式的連結

multi_lookup(EtsTable, Key)

檢視原始碼
-spec multi_lookup(EtsTable, Key) -> Result
                      when EtsTable :: ets:tid(), Key :: term(), Result :: list() | [term()].

multi_lookupETSTable 中提取所有 {Key, Value} 元組,並在列表中返回與 Key 關聯的所有 Values

此函式的連結

reason_phrase(StatusCode)

檢視原始碼
-spec reason_phrase(StatusCode) -> Description
                       when
                           StatusCode ::
                               100 | 101 | 102 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 226 |
                               300 | 301 | 302 | 303 | 304 | 305 | 306 | 307 | 308 | 400 | 401 | 402 |
                               403 | 404 | 405 | 406 | 407 | 408 | 409 | 410 | 411 | 412 | 413 | 414 |
                               415 | 416 | 417 | 422 | 423 | 424 | 425 | 426 | 500 | 501 | 502 | 503 |
                               504 | 505 | 507,
                           Description :: string().

reason_phrase 返回 HTTP 1.1 StatusCodeDescription,例如,200 是 "OK",201 是 "Created"。如需更多資訊,請參閱 RFC 2616

-spec rfc1123_date() -> RFC1123Date when RFC1123Date :: string().

等同於 rfc1123_date/1

此函式的連結

rfc1123_date(LocalTime)

檢視原始碼
-spec rfc1123_date(LocalTime) -> RFC1123Date
                      when
                          LocalTime :: calendar:datetime() | undefined,
                          RFC1123Date :: string() | undefined.

rfc1123_date/0 以 RFC 1123 格式返回當前日期。rfc_date/1 將 Erlang 格式的日期轉換為 RFC 1123 日期格式。

此函式的連結

split(String, RegExp, N)

檢視原始碼
-spec split(String, RegExp, N) -> SplitRes
               when
                   String :: string(),
                   RegExp :: string(),
                   N :: non_neg_integer(),
                   SplitRes :: {ok, FieldList} | {error, term()},
                   FieldList :: [string()].

split/3 使用 RegExpString 分割為 N 個區塊。split/3 等同於 re:split/3,但 N 定義了 FieldList 中欄位的最大數目。

-spec split_path(URIString) -> {Path, QueryStringOrPathInfo}
                    when URIString :: string(), Path :: string(), QueryStringOrPathInfo :: string().

split_path/1RequestLine 分割為檔案參考 (Path) 以及 RFC 2616 中指定的 QueryStringPathInfo 字串。QueryString 以問號 (?) 與 Path 隔離,而 PathInfo 以斜線 (/) 隔離。在 QueryString 的情況下,? 之前的所有內容都是 Path,而 ? 之後的所有內容都是 QueryString。在 PathInfo 的情況下,從左到右掃描 RequestLine,以尋找最長的可能 Path,該 Path 為檔案或目錄。最長可能 Path 之後的所有內容,以 / 隔離,都視為 PathInfo

此函式的連結

split_script_path(URIString)

檢視原始碼
-spec split_script_path(URIString) -> Split
                           when
                               URIString :: string(),
                               Split :: not_a_script | {Path, {PathInfo, QueryString}} | {Path, []},
                               Path :: string(),
                               QueryString :: string(),
                               PathInfo :: string().

split_script_path/1 等同於 split_path/1,但有一個例外。如果最長可能的路徑不是常規、可存取且可執行的檔案,則返回 not_a_script