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

一個 HTTP/1.1 用戶端

此模組根據 RFC 2616 提供與 HTTP/1.1 相容的用戶端 API。不支援快取。

注意

當啟動 Inets 應用程式時,會為預設設定檔啟動一個管理程序。此 API 中未明確使用設定檔的函式會存取預設設定檔。設定檔會追蹤代理選項、Cookie 和其他可應用於多個請求的選項。

如果使用 https 協定,則必須啟動 SSL 應用程式。當 https 連結需要通過代理伺服器時,會使用 HTTP-1.1 的 CONNECT 方法延伸來建立通道,然後將連線升級為 TLS。但是,不支援根據 RFC 2817 的「TLS 升級」。

只有在設定管線逾時時才會使用管線化,否則會使用沒有管線化的持久連線。也就是說,用戶端在傳送下一個請求之前總是會等待前一個回應。

Inets 使用者指南中提供了一些範例。

HTTP 用戶端服務啟動與停止

可以設定 HTTP 用戶端在啟動 Inets 應用程式時啟動,或在執行階段透過呼叫 Inets 應用程式 API inets:start(httpc, ServiceConfig)inets:start(httpc, ServiceConfig, How) 動態啟動,請參閱 inets。組態選項如下:

  • {profile, Profile :: atom() | pid()} - 設定檔的名稱。此選項為強制選項。

  • {data_dir, Path :: string()} - 設定檔可以儲存持久資料的目錄。如果省略,所有 Cookie 都會被視為工作階段 Cookie。Path 代表檔案路徑或目錄路徑。

可以使用 inets:stop(httpc, Pid)inets:stop(httpc, Profile) 來停止用戶端。

警告

請注意,httpc 在內部處理之前會正規化輸入 URI,並且當 URI 具有百分比 ("%") 字元時,應特別注意。百分比用作百分比編碼八位元組的指示符,並且必須將其百分比編碼為 "%25",以便該八位元組用作 URI 中的資料。

例如,為了傳送具有 URI https://127.0.0.1/foo%25barHTTP GET 請求,在建立請求時必須對百分比字元進行百分比編碼:httpc:request("https://127.0.0.1/foo%2525bar").

另請參閱

RFC 2616inetsgen_tcpssl

摘要

函式

取消非同步 HTTP 請求。請注意,這不能保證不傳遞請求回應。由於它是非同步的,因此當取消到達時,請求可能已完成。

傳回在使用設定檔 ProfileUrl 發出請求時會傳送的 Cookie 標頭。如果未指定設定檔,則會使用預設設定檔。

傳回在使用設定檔 ProfileUrl 發出請求時會傳送的 Cookie 標頭。如果未指定設定檔,則會使用預設設定檔。

擷取用戶端目前使用的選項。

等同於 info/1

產生雜項資訊的清單。用於除錯。如果未指定設定檔,則會使用預設設定檔。

等同於 request/2

傳送 HTTP 請求。此函式可以是同步或非同步的。在後一種情況下,此函式會傳回 {ok, RequestId},然後根據該值將資訊傳遞至 receiver

重設 (清除) 指定 Profile 的 Cookie 資料庫。如果未指定設定檔,則會使用預設設定檔。

設定要用於後續請求的選項。

傳回可用於驗證主機的 SSL 選項,使用 public_key:cacerts_get() 讀取 CA 憑證,如果 WildcardHostName 為 true,則將來自 public_key:public_key:pkix_verify_hostname_match_fun(https) 的主機名稱檢查新增至選項。

SetCookieHeaders 中定義的 Cookie 儲存在用戶端設定檔 Cookie 資料庫中。如果選項 cookies 設定為 verify,則呼叫此函式。如果未指定設定檔,則會使用預設設定檔。

觸發要串流的下一個訊息,也就是與 Socket 的活動行為相同。

產生整個 Cookie 資料庫的清單。用於除錯/測試目的。如果未指定設定檔,則會使用預設設定檔。

此函式僅用於除錯。它會產生工作階段資料庫的稍作處理的傾印。工作階段資訊元組的第一個清單將包含內部格式的工作階段資訊。如果程式碼按預期運作,工作階段資訊元組的最後兩個清單應始終為空。如果未指定設定檔,則會使用預設設定檔。

函式

連結到此函式

cancel_request(RequestId)

檢視原始碼 (自 OTP R13B04 起)
-spec cancel_request(RequestId) -> ok when RequestId :: any().

等同於 cancel_request/2

連結到此函式

cancel_request(RequestId, Profile)

檢視原始碼 (自 OTP R13B04 起)
-spec cancel_request(RequestId, Profile) -> ok when RequestId :: any(), Profile :: atom() | pid().

取消非同步 HTTP 請求。請注意,這不能保證不傳遞請求回應。由於它是非同步的,因此當取消到達時,請求可能已完成。

連結到此函式

get_options(OptionItems)

檢視原始碼 (自 OTP R15B01 起)
-spec get_options(OptionItems) -> {ok, Values} | {error, Reason}
                     when
                         OptionItems :: all | [OptionItem],
                         OptionItem ::
                             proxy | https_proxy | max_sessions | keep_alive_timeout |
                             max_keep_alive_length | pipeline_timeout | max_pipeline_length | cookies |
                             ipfamily | ip | port | socket_opts | verbose | unix_socket,
                         Values :: [{OptionItem, term()}],
                         Reason :: term().

等同於 get_options/2

連結到此函式

get_options(OptionItems, Profile)

檢視原始碼 (自 OTP R15B01 起)
-spec get_options(OptionItems, Profile) -> {ok, Values} | {error, Reason}
                     when
                         OptionItems :: all | [OptionItem],
                         OptionItem ::
                             proxy | https_proxy | max_sessions | keep_alive_timeout |
                             max_keep_alive_length | pipeline_timeout | max_pipeline_length | cookies |
                             ipfamily | ip | port | socket_opts | verbose | unix_socket,
                         Values :: [{OptionItem, term()}],
                         Profile :: atom() | pid(),
                         Reason :: term().

擷取用戶端目前使用的選項。

連結到此函式

info()

檢視原始碼 (自 OTP R15B02 起)
-spec info() -> list() | {error, Reason} when Reason :: term().

等同於 info/1

連結到此函式

info(Profile)

檢視原始碼 (自 OTP R15B02 起)
-spec info(Profile) -> list() | {error, Reason} when Reason :: term(), Profile :: atom() | pid().

產生雜項資訊的清單。用於除錯。如果未指定設定檔,則會使用預設設定檔。

連結到此函式

request(Url)

檢視原始碼 (自 OTP R13B04 起)
-spec request(uri_string:uri_string()) -> {ok, Result} | {error, term()}
                 when
                     Result ::
                         {StatusLine :: {HttpVersion, StatusCode, string()},
                          [HttpHeader],
                          HttpBodyResult} |
                         {StatusCode, HttpBodyResult} |
                         RequestId | saved_to_file,
                     HttpBodyResult :: uri_string:uri_string() | binary(),
                     HttpVersion :: uri_string:uri_string(),
                     StatusCode :: non_neg_integer(),
                     HttpHeader :: {Field :: [byte()], Value :: binary() | iolist()},
                     RequestId :: any().

等同於 request/2

連結到此函式

request(Url, Profile)

檢視原始碼 (自 OTP R13B04 起)
-spec request(Url, Profile) -> {ok, Result} | {error, term()}
                 when
                     Url :: uri_string:uri_string(),
                     Profile :: atom() | pid(),
                     Result ::
                         {StatusLine, [HttpHeader], HttpBodyResult} |
                         {StatusCode, HttpBodyResult} |
                         RequestId | saved_to_file,
                     HttpHeader :: {Field :: [byte()], Value :: binary() | iolist()},
                     HttpBodyResult :: uri_string:uri_string() | binary(),
                     StatusLine :: {HttpVersion, StatusCode, string()},
                     HttpVersion :: uri_string:uri_string(),
                     StatusCode :: non_neg_integer(),
                     RequestId :: any().

等同於 httpc:request(get, {Url, []}, [], [])

連結到此函式

request(Method, Request, HttpOptions, Options)

檢視原始碼 (自 OTP R13B04 起)
-spec request(Method, Request, HttpOptions, Options) -> {ok, Result} | {error, term()}
                 when
                     Method :: head | get | put | patch | post | trace | options | delete,
                     Request ::
                         {uri_string:uri_string(), [HttpHeader]} |
                         {uri_string:uri_string(),
                          [HttpHeader],
                          ContentType :: uri_string:uri_string(),
                          HttpBody},
                     HttpBody ::
                         iolist() |
                         binary() |
                         {fun((Accumulator :: term()) -> eof | {ok, iolist(), Accumulator :: term()}),
                          Accumulator :: term()} |
                         {chunkify,
                          fun((Accumulator :: term()) -> eof | {ok, iolist(), Accumulator :: term()}),
                          Accumulator :: term()},
                     HttpOptions :: [HttpOption],
                     HttpOption ::
                         {timeout, timeout()} |
                         {connect_timeout, timeout()} |
                         {ssl, [ssl:tls_option()]} |
                         {autoredirect, boolean()} |
                         {proxy_auth, {string(), string()}} |
                         {version, HttpVersion} |
                         {relaxed, boolean()},
                     Options :: [OptionRequest],
                     OptionRequest ::
                         {sync, boolean()} |
                         {stream, StreamTo} |
                         {body_format, BodyFormat} |
                         {full_result, boolean()} |
                         {headers_as_is, boolean()} |
                         {socket_opts, [SocketOpt]} |
                         {receiver, Receiver} |
                         {ipv6_host_with_brackets, boolean()},
                     StreamTo :: none | self | {self, once} | file:name_all(),
                     SocketOpt :: term(),
                     BodyFormat :: string | binary,
                     Receiver ::
                         pid() |
                         fun((term()) -> term()) |
                         {ReceiverModule :: atom(), ReceiverFunction :: atom(), ReceiverArgs :: list()},
                     Result ::
                         {StatusLine, [HttpHeader], HttpBodyResult} |
                         {StatusCode, HttpBodyResult} |
                         RequestId | saved_to_file,
                     StatusCode :: non_neg_integer(),
                     StatusLine :: {HttpVersion, StatusCode, string()},
                     HttpVersion :: uri_string:uri_string(),
                     HttpHeader :: {Field :: [byte()], Value :: binary() | iolist()},
                     HttpBodyResult :: uri_string:uri_string() | binary(),
                     RequestId :: any().

等同於 request/5

連結到此函式

request(Method, Request, HttpOptions, Options, Profile)

檢視原始碼 (自 OTP R13B04 起)
-spec request(Method, Request, HttpOptions, Options, Profile) -> {ok, Result} | {error, term()}
                 when
                     Method :: head | get | put | patch | post | trace | options | delete,
                     Request ::
                         {uri_string:uri_string(), [HttpHeader]} |
                         {uri_string:uri_string(),
                          [HttpHeader],
                          ContentType :: uri_string:uri_string(),
                          HttpBody},
                     HttpBody ::
                         iolist() |
                         binary() |
                         {fun((Accumulator :: term()) -> eof | {ok, iolist(), Accumulator :: term()}),
                          Accumulator :: term()} |
                         {chunkify,
                          fun((Accumulator :: term()) -> eof | {ok, iolist(), Accumulator :: term()}),
                          Accumulator :: term()},
                     HttpHeader :: {Field :: [byte()], Value :: binary() | iolist()},
                     HttpOptions :: [HttpOption],
                     HttpOption ::
                         {timeout, timeout()} |
                         {connect_timeout, timeout()} |
                         {ssl, [ssl:tls_option()]} |
                         {autoredirect, boolean()} |
                         {proxy_auth, {string(), string()}} |
                         {version, HttpVersion} |
                         {relaxed, boolean()},
                     Options :: [OptionRequest],
                     OptionRequest ::
                         {sync, boolean()} |
                         {stream, StreamTo} |
                         {body_format, BodyFormat} |
                         {full_result, boolean()} |
                         {headers_as_is, boolean()} |
                         {socket_opts, [SocketOpt]} |
                         {receiver, Receiver} |
                         {ipv6_host_with_brackets, boolean()},
                     StreamTo :: none | self | {self, once} | file:name_all(),
                     BodyFormat :: string | binary,
                     SocketOpt :: term(),
                     Receiver ::
                         pid() |
                         fun((term()) -> term()) |
                         {ReceiverModule :: atom(), ReceiverFunction :: atom(), ReceiverArgs :: list()},
                     Profile :: atom() | pid(),
                     HttpVersion :: uri_string:uri_string(),
                     Result ::
                         {StatusLine, [HttpHeader], HttpBodyResult} |
                         {StatusCode, HttpBodyResult} |
                         RequestId | saved_to_file,
                     StatusLine :: {HttpVersion, StatusCode, string()},
                     StatusCode :: non_neg_integer(),
                     HttpBodyResult :: uri_string:uri_string() | binary(),
                     RequestId :: any().

傳送 HTTP 請求。此函式可以是同步或非同步的。在後一種情況下,此函式會傳回 {ok, RequestId},然後根據該值將資訊傳遞至 receiver

Profilestand_alone 時,只能使用 pid。

HTTP 選項

  • timeout - 請求的逾時時間。

    時鐘會在傳送請求時開始計時。

    時間以毫秒為單位。

    預設值為 infinity

  • connect_timeout - 連線逾時時間,用於初始請求期間,當用戶端正在連線到伺服器時。

    時間以毫秒為單位。

    預設值為選項 timeout 的值。

  • ssl - 此為 SSL/TLS 連線設定選項。

    預設值透過呼叫 httpc:ssl_verify_host_options(true) 取得。請參閱 ssl:connect/2,3,4 以了解可用的選項。

  • autoredirect - 用戶端會自動從新的 URI 擷取資訊,並將其作為結果傳回,而不是 30X 狀態碼。

    對於某些 30X 狀態碼,不允許自動重新導向。在這些情況下,始終會傳回 30X 狀態碼。

    預設值為 true

  • proxy_auth - 使用元組的 Proxy-Authorization 標頭,其中第一個元素是 username,元組的第二個元素是加入至請求的 password

  • version - 可用來讓用戶端作為 HTTP/1.0 用戶端。預設情況下,此為 HTTP/1.1 用戶端。使用 HTTP/1.0 時,不會使用持續性連線。

    預設值為字串 "HTTP/1.1"

  • relaxed - 若設為 true,則會啟用針對已知伺服器偏離 HTTP 標準的變通方法。

    預設值為 false

選項詳細資訊

  • sync - 用於請求是否為同步或非同步的選項。

    預設值為 true

  • stream - 將 200 或 206 回應的主體串流至呼叫程序或檔案。當使用選項 self 串流至呼叫程序時,以下串流訊息會傳送至該程序:{http, {RequestId, stream_start, Headers}}, {http, {RequestId, stream, BinBodyPart}}, and {http, {RequestId, stream_end, Headers}}

    當使用選項 {self, once} 串流至呼叫程序時,第一個訊息會有額外元素,即 {http, {RequestId, stream_start, Headers, Pid}}。這是要作為 httpc:stream_next/1 的引數使用的程序 ID,以觸發傳送至呼叫程序的下一個訊息。

    請注意,分塊編碼可以新增標頭,因此 stream_end 訊息中的標頭會比 stream_start 中的標頭多。當串流至檔案且請求為非同步時,會傳送訊息 {http, {RequestId, saved_to_file}}

    預設值為 none

  • body_format - 定義主體是要以字串還是二進位形式傳遞。此選項僅適用於同步請求。

    預設值為 string

  • full_result - 定義是否要將「完整結果」傳回給呼叫者 (即主體、標頭和整個狀態列),還是不要 (主體和狀態碼)。

    預設值為 true

  • headers_as_is - 定義使用者提供的標頭是要轉換為小寫,還是視為區分大小寫。

    HTTP 標準要求標頭不區分大小寫。只有在沒有其他方法與伺服器通訊或用於測試目的時,才應使用此功能。使用此選項時,不會自動新增任何標頭。所有必要的標頭都必須由使用者提供。

    預設值為 false

  • socket_opts - 用於此請求的 Socket 選項。

    請參閱 gen_tcpssl 使用的選項

    覆寫函數 set_options 設定的任何值。

    HTTP 用戶端「不會」檢查選項的有效性,它們會被假設為正確,並傳遞至 ssl 應用程式和 inet 驅動程式,如果選項不正確,它們可能會拒絕這些選項。

    注意

    設定 socket_opts 選項時,不支援持續性連線。當未設定 socket_opts 時,目前的實作會假設對相同主機、埠組合的請求將使用相同的 Socket 選項。

    預設情況下,建立連線時會使用函數 set_options/1,2 設定的 Socket 選項。

  • receiver - 定義用戶端如何傳遞非同步請求的結果 (sync 的值為 false)。

    • pid/0 - 訊息會以 {http, ReplyInfo} 格式傳送至此程序。

    • alias/0 - 訊息會以 {http, ReplyInfo} 格式傳送至此特殊參考。

    • function/1 - 資訊會透過呼叫提供的函數 Receiver(ReplyInfo) 傳遞給接收者。

    • {Module, Function, Args} - 資訊會透過呼叫回呼函數 apply(Module, Function, [ReplyInfo | Args]) 傳遞給接收者。

    在所有這些情況下,ReplyInfo 都具有以下結構

     {RequestId, saved_to_file}
     {RequestId, {error, Reason}}
     {RequestId, Result}
     {RequestId, stream_start, Headers}
     {RequestId, stream_start, Headers, HandlerPid}
     {RequestId, stream, BinBodyPart}
     {RequestId, stream_end, Headers}

    預設值為呼叫請求函數的程序的 pid (self/0)。

  • ipv6_host_with_brackets - 定義當剖析具有 IPv6 位址 (帶括號) 的 URI 的主機埠部分時,是否要保留這些括號 (true) 或去除括號 (false)。

    預設值為 false

連結到此函式

reset_cookies()

檢視原始碼 (自 OTP R13B04 起)
-spec reset_cookies() -> Void when Void :: term().

等同於 reset_cookies/1

連結到此函式

reset_cookies(Profile)

檢視原始碼 (自 OTP R13B04 起)
-spec reset_cookies(Profile) -> Void when Profile :: atom() | pid(), Void :: term().

重設 (清除) 指定 Profile 的 Cookie 資料庫。如果未指定設定檔,則會使用預設設定檔。

連結到此函式

set_options(Options)

檢視原始碼 (自 OTP R13B04 起)
-spec set_options(Options) -> ok | {error, Reason}
                     when
                         Options :: [Option],
                         Option ::
                             {proxy, {Proxy, NoProxy}} |
                             {https_proxy, {Proxy, NoProxy}} |
                             {max_sessions, MaxSessions} |
                             {max_keep_alive_length, MaxKeepAlive} |
                             {keep_alive_timeout, KeepAliveTimeout} |
                             {max_pipeline_length, MaxPipeline} |
                             {pipeline_timeout, PipelineTimeout} |
                             {cookies, CookieMode} |
                             {ipfamily, IpFamily} |
                             {ip, IpAddress} |
                             {port, Port} |
                             {socket_opts, SocketOpts} |
                             {verbose, VerboseMode} |
                             {unix_socket, UnixSocket},
                         Proxy :: {HostName, Port},
                         Port :: non_neg_integer(),
                         NoProxy :: [DomainDesc | HostName | IpAddressDesc],
                         MaxSessions :: integer(),
                         MaxKeepAlive :: integer(),
                         KeepAliveTimeout :: integer(),
                         MaxPipeline :: integer(),
                         PipelineTimeout :: integer(),
                         CookieMode :: enabled | disabled | verify,
                         IpFamily :: inet | inet6 | local | inet6fb4,
                         IpAddressDesc :: uri_string:uri_string(),
                         IpAddress :: inet:ip_address(),
                         VerboseMode :: false | verbose | debug | trace,
                         SocketOpts :: [SocketOpt],
                         SocketOpt :: term(),
                         UnixSocket :: file:name_all(),
                         Reason :: term(),
                         DomainDesc :: string(),
                         HostName :: uri_string:uri_string().

等同於 set_options/2

連結到此函式

set_options(Options, Profile)

檢視原始碼 (自 OTP R13B04 起)
-spec set_options(Options, Profile) -> ok | {error, Reason}
                     when
                         Options :: [Option],
                         Option ::
                             {proxy, {Proxy, NoProxy}} |
                             {https_proxy, {Proxy, NoProxy}} |
                             {max_sessions, MaxSessions} |
                             {max_keep_alive_length, MaxKeepAlive} |
                             {keep_alive_timeout, KeepAliveTimeout} |
                             {max_pipeline_length, MaxPipeline} |
                             {pipeline_timeout, PipelineTimeout} |
                             {cookies, CookieMode} |
                             {ipfamily, IpFamily} |
                             {ip, IpAddress} |
                             {port, Port} |
                             {socket_opts, [SocketOpt]} |
                             {verbose, VerboseMode} |
                             {unix_socket, UnixSocket},
                         Profile :: atom() | pid(),
                         SocketOpt :: term(),
                         Proxy :: {HostName, Port},
                         Port :: non_neg_integer(),
                         NoProxy :: [DomainDesc | HostName | IpAddressDesc],
                         MaxSessions :: integer(),
                         MaxKeepAlive :: integer(),
                         KeepAliveTimeout :: integer(),
                         MaxPipeline :: integer(),
                         PipelineTimeout :: integer(),
                         CookieMode :: enabled | disabled | verify,
                         IpFamily :: inet | inet6 | local | inet6fb4,
                         IpAddressDesc :: uri_string:uri_string(),
                         IpAddress :: inet:ip_address(),
                         VerboseMode :: false | verbose | debug | trace,
                         UnixSocket :: string(),
                         Reason :: term(),
                         DomainDesc :: string(),
                         HostName :: uri_string:uri_string().

設定要用於後續請求的選項。

  • HostName - 範例:「localhost」或「foo.bar.se」

  • DomainDesc - 範例 "*.Domain""*.ericsson.se"

  • IpAddressDesc - 範例:「134.138」或「[FEDC:BA98」(所有以 134.138 或 FEDC:BA98 開頭的 IP 位址)、「66.35.250.150」或「[2010:836B:4179::836B:4179]」(完整的 IP 位址)。proxy 預設為 {undefined, []},即未設定 Proxy,https_proxy 預設為 proxy 的值。

  • MaxSessions - MaxSessions 主機持續性連線的最大數目。預設值為 2

  • MaxKeepAlive - MaxKeepAlive 對主機的相同連線的未完成請求的最大數目。預設值為 5

  • KeepAliveTimeout - KeepAliveTimeout 如果持續性連線閒置的時間長度超過 keep_alive_timeout (以毫秒為單位),用戶端將關閉連線。伺服器也可能會有此類逾時,但不要認為理所當然。預設值為 120000 (= 2 分鐘)。

  • MaxPipeline - MaxPipeline 對主機的管線連線的未完成請求的最大數目。預設值為 2

  • PipelineTimeout - PipelineTimeout 如果持續性連線閒置的時間長度超過 pipeline_timeout (以毫秒為單位),用戶端將關閉連線。預設值為 0,這會導致不使用管線。

  • CookieMode - 如果啟用 Cookie,所有有效的 Cookie 都會自動儲存在用戶端管理員的 Cookie 資料庫中。如果使用選項 verify,則必須呼叫函數 store_cookies/2 才能儲存 Cookie。預設值為 disabled

  • IpFamily - 預設值為 inet。使用 inet6fb4 選項,會優先使用 IPv6,但如果連線失敗,將會嘗試進行 IPv4 後援連線。

  • IpAddress - 如果主機有多個網路介面,此選項會指定要使用哪一個。如需詳細資訊,請參閱 gen_tcp:connect/3,4

  • Port - 範例:8080。要使用的本機埠號碼。如需詳細資訊,請參閱 gen_tcp:connect/3,4

  • SocketOpts - 這些選項會附加至用戶端使用的 Socket 選項。這些是在啟動新的請求處理常式時 (對於初始連線) 的預設值。它們會直接傳遞至基礎傳輸 (gen_tcpSSL),而無需驗證。

    請參閱 gen_tcpssl 使用的選項

  • VerboseMode - 預設值為 false。此選項用於開啟 (或關閉) 用戶端上的不同層級的 Erlang 追蹤。這是一項偵錯功能。

  • Profile - 啟動 stand_alone 時,只能使用 pid。

  • UnixSocket - 用於透過 Unix 網域 Socket 傳送 HTTP 請求的實驗性選項。unix_socket 的值應為 Unix 網域 Socket 檔案的完整路徑,該檔案具有 Erlang 程序的讀/寫權限。預設值為 undefined

注意

如果可以,用戶端會保持連線作用中,並使用持續性連線 (無論有無管線),具體取決於設定和目前情況。HTTP/1.1 規格未提供關於在持續性連線上傳送多少請求是理想的指南。這很大程度上取決於應用程式。

長時間的請求佇列可能會導致使用者察覺到延遲,因為較早的請求可能需要很長時間才能完成。HTTP/1.1 規格建議每個伺服器的持續性連線限制為兩個,這是選項 max_sessions 的預設值。

目前的實作假設對相同主機、埠組合的請求將使用相同的 Socket 選項。

連結到此函式

ssl_verify_host_options(WildcardHostName)

檢視原始碼 (自 OTP 25.1 起)
-spec ssl_verify_host_options(WildcardHostName) -> list() when WildcardHostName :: boolean().

傳回可用於驗證主機的 SSL 選項,使用 public_key:cacerts_get() 讀取 CA 憑證,如果 WildcardHostName 為 true,則將來自 public_key:public_key:pkix_verify_hostname_match_fun(https) 的主機名稱檢查新增至選項。

連結到此函式

store_cookies(SetCookieHeaders, Url)

檢視原始碼 (自 OTP R14B02 起)
-spec store_cookies(SetCookieHeaders, Url) -> ok | {error, Reason}
                       when
                           SetCookieHeaders :: [HttpHeader],
                           HttpHeader :: {Field :: [byte()], Value :: binary() | iolist()},
                           Url :: term(),
                           Reason :: term().

等同於 store_cookies/3

連結到此函式

store_cookies(SetCookieHeaders, Url, Profile)

檢視原始碼 (自 OTP R14B02 起)
-spec store_cookies(SetCookieHeaders, Url, Profile) -> ok | {error, Reason}
                       when
                           SetCookieHeaders :: [HttpHeader],
                           HttpHeader :: {Field :: [byte()], Value :: binary() | iolist()},
                           Url :: term(),
                           Profile :: atom() | pid(),
                           Reason :: term().

SetCookieHeaders 中定義的 Cookie 儲存在用戶端設定檔 Cookie 資料庫中。如果選項 cookies 設定為 verify,則呼叫此函式。如果未指定設定檔,則會使用預設設定檔。

連結到此函式

stream_next(Pid)

檢視原始碼 (自 OTP R13B04 起)
-spec stream_next(Pid) -> ok when Pid :: pid().

觸發要串流的下一個訊息,也就是與 Socket 的活動行為相同。

連結到此函式

which_cookies()

檢視原始碼 (自 OTP R13B04 起)
-spec which_cookies() -> [CookieStores]
                       when
                           CookieStores :: {cookies, Cookies} | {session_cookies, Cookies},
                           Cookies :: [term()].

等同於 which_cookies/1

連結到此函式

which_cookies(Profile)

檢視原始碼 (自 OTP R13B04 起)
-spec which_cookies(Profile) -> [CookieStores]
                       when
                           Profile :: atom() | pid(),
                           CookieStores :: {cookies, Cookies} | {session_cookies, Cookies},
                           Cookies :: [term()].

產生整個 Cookie 資料庫的清單。用於除錯/測試目的。如果未指定設定檔,則會使用預設設定檔。

連結到此函式

which_sessions()

檢視原始碼 (自 OTP R15B02 起)
-spec which_sessions() -> SessionInfo
                        when
                            SessionInfo :: {GoodSession, BadSessions, NonSessions},
                            GoodSession :: [Session],
                            BadSessions :: [term()],
                            NonSessions :: [term()],
                            Session :: term().

等同於 which_sessions/1

連結到此函式

which_sessions(Profile)

檢視原始碼 (自 OTP R15B02 起)
-spec which_sessions(Profile) -> SessionInfo
                        when
                            Profile :: atom() | pid(),
                            SessionInfo :: {GoodSession, BadSessions, NonSessions},
                            GoodSession :: [Session],
                            BadSessions :: [term()],
                            NonSessions :: [term()],
                            Session :: term().

此函式僅用於除錯。它會產生工作階段資料庫的稍作處理的傾印。工作階段資訊元組的第一個清單將包含內部格式的工作階段資訊。如果程式碼按預期運作,工作階段資訊元組的最後兩個清單應始終為空。如果未指定設定檔,則會使用預設設定檔。