Skip to content
This repository
Fetching contributors…

Cannot retrieve contributors at this time

file 103 lines (79 sloc) 3.162 kb
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

<erl>

out(A) ->
       {ssi, "TAB.inc", "%%",[{"arg", "choosen"}]}.

</erl>

<div id="entry">

<h2> The Arg </h2>

  <p>This page displays the Arg #arg structure
    supplied to the out/1 function.
  </p>
  <p> The #arg structure is a very important datastructure for the
    yaws programmer. It is the main mechanism whereby the server can pass
    data to the web application. There are several data items
    which are of interest to the webapplication, such as which headers
    were sent from the client, etc.
    The #arg recored is defined in <tt>yaws_api.hrl</tt> and is defined as:
  </p>
  <div class="box">
    <pre>


-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: &lt;appmod&gt;&lt;appmoddata&gt;
          pathinfo %% Set to 'd/e' when calling c.yaws for the request
                          %% http://some.host/a/b/c.yaws/d/e
         }).

    </pre>
  </div>

  <p> As we have seen is several previous examples,
    the <tt> out/1</tt> function
    defined in .yaws files, gets invoked with a single argument which is
    a #arg{} record, fitting the specific HTTP request being served.
  </p>

  <p> The code to display the #arg{} record
    is in defined in file <a href="code.yaws?file=/arg2.yaws">arg2.yaws</a>
    and is invoked at <a href="arg2.yaws">arg2.yaws</a>
  </p>

<erl>

out(A) ->

    Peer = A#arg.client_ip_port,
    Req = A#arg.req,
    H = yaws_api:reformat_header(A#arg.headers),
    {ehtml,
     [{h5,[], "The headers passed to us were:"},
      {hr,[],[]},
      {ol, [],lists:map(fun(S) -> {li,[], {p,[],S}} end,H)},

      {h5, [], "The request"},
      {ul,[],
       [{li,[], f("method: ~s", [Req#http_request.method])},
        {li,[], f("path: ~p", [Req#http_request.path])},
        {li,[], f("version: ~p", [Req#http_request.version])}]},

      {hr,[],[]},
      {h5, [], "Other items"},
      {ul,[],
       [{li, [], f("Peer: ~p", [Peer])},
        {li,[], f("docroot: ~s", [A#arg.docroot])},
        {li,[], f("fullpath: ~s", [A#arg.fullpath])}]},
      {hr,[],[]},
      {h5, [], "Parsed query data"},
      {pre,[], f("~p", [yaws_api:parse_query(A)])},
      {hr,[],[]},
      {h5,[], "Parsed POST data "},
      {pre,[], f("~p", [yaws_api:parse_post(A)])}]}.

</erl>





</div>


<erl>
out(A) -> {ssi, "END2",[],[]}.
</erl>
Something went wrong with that request. Please try again.