跳至内容

Erlang 编程/使用 yaws 创建 Web 应用程序/Arg 结构

来自维基教科书,开放世界的开放书籍

Arg 数据结构是服务器用来向 Web 应用程序转发基本信息的主要机制。在yaws_api.hrl 中定义 #arg 记录,定义如下

-record(arg, {
          clisock,        %% the socket leading to the peer client
          client_ip_port, %% {Ip, Port} for the client
          headers,        %% headers
          req,            %% request
          clidata,        %% The client data (as a binary in POST requests)
          server_path,    %% The normalized server path
          querydata,      %% Was the URL on the form of ...?query (GET reqs)
          appmoddata,     %% the remainder of the path leading up to the query
          docroot,        %% where's the data
          fullpath,       %% full deep path to yaws file
          cont,           %% Continuation for chunked multipart uploads
          state,          %% State for use by users of the out/1 callback
          pid,            %% pid of the yaws worker process
          opaque,         %% useful to pass static data
          appmod_prepath, %% path in front of: <appmod><appmoddata>
          pathinfo        %% Set to 'd/e' when calling c.yaws for the request
                          %% http://some.host/a/b/c.yaws/d/e
         }).

Arg 结构中的一些参数包含其他信息,如下所示。

-record(headers, {
          connection,
          accept,
          host,
          if_modified_since,
          if_match,
          if_none_match,
          if_range,
          if_unmodified_since,
          range,
          referer,
          user_agent,
          accept_ranges,
          cookie = [],
          keep_alive,
          content_length,
          authorization,
          other = []   %% misc other headers
         }).
华夏公益教科书