lfe-http / http

General purpose data, functions, and utilties for use by LFE/Erlang HTTP clients, servers, URL-parsers, web frameworks, etc.
Apache License 2.0
1 stars 0 forks source link

Add data abstraction for request #2

Closed oubiwann closed 1 year ago

oubiwann commented 1 year ago

Refer to lhc, and update lhc to use this.

And this: https://github.com/lfex/barista/blob/main/src/barista-request.lfe

oubiwann commented 1 year ago

inets:

#request{method        = Method, 
     path          = Path, 
         pquery        = Query, 
     headers       = Headers,
     content       = Content, 
     address       = Address, 
     abs_uri       = AbsUri, 
     headers_as_is = HeadersAsIs,
     settings      = HttpOptions, 
     userinfo      = UserInfo}) 
oubiwann commented 1 year ago

cowboy:

-type req() :: #{
    %% Public interface.
    method := binary(),
    version := cowboy:http_version() | atom(),
    scheme := binary(),
    host := binary(),
    port := inet:port_number(),
    path := binary(),
    qs := binary(),
    headers := cowboy:http_headers(),
    peer := {inet:ip_address(), inet:port_number()},
    sock := {inet:ip_address(), inet:port_number()},
    cert := binary() | undefined,

    %% Private interface.
    ref := ranch:ref(),
    pid := pid(),
    streamid := cowboy_stream:streamid(),

    host_info => cowboy_router:tokens(),
    path_info => cowboy_router:tokens(),
    bindings => cowboy_router:bindings(),

    has_body := boolean(),
    body_length := non_neg_integer() | undefined,
    has_read_body => true,
    multipart => {binary(), binary()} | done,

    has_sent_resp => headers | true,
    resp_cookies => #{iodata() => iodata()},
    resp_headers => #{binary() => iodata()},
    resp_body => resp_body(),

    proxy_header => ranch_proxy_header:proxy_info(),
    media_type => {binary(), binary(), [{binary(), binary()}]},
    language => binary() | undefined,
    charset => binary() | undefined,
    range => {binary(), binary()
        | [{non_neg_integer(), non_neg_integer() | infinity} | neg_integer()]},
    websocket_version => 7 | 8 | 13,

    %% The user is encouraged to use the Req to store information
    %% when no better solution is available.
    _ => _
}.
oubiwann commented 1 year ago

elli:

-record(req, {method           :: elli:http_method(),
              scheme           :: undefined | binary(),
              host             :: undefined | binary(),
              port             :: undefined | 1..65535,
              path             :: [binary()],
              args             :: [{binary(), any()}],
              raw_path         :: binary(),
              version          :: elli_http:version(),
              headers          :: elli:headers(),
              original_headers :: elli:headers(),
              body             :: elli:body(),
              pid              :: pid(),
              socket           :: undefined | elli_tcp:socket(),
              callback         :: elli_handler:callback()
             }).
oubiwann commented 1 year ago

dlhttpc:

%% @spec (ReqId, From, Host, Port, Ssl, Path, Method, Hdrs, RequestBody, Options) -> ok
%%    ReqId = term()
%%    From = pid()
%%    Host = string()
%%    Port = integer()
%%    Ssl = boolean()
%%    Method = atom() | string()
%%    Hdrs = [Header]
%%    Header = {string() | atom(), string()}
%%    Body = iolist()
%%    Options = [Option]
%%    Option = {connect_timeout, Milliseconds}
%% @end
oubiwann commented 1 year ago

hackney:

-record(client,  {
  start_time,
  mod_metrics = nil,
  transport,
  host,
  port,
  netloc,
  options = [],
  socket = nil,
  socket_ref = nil,
  request_ref = nil,
  dynamic = true,
  pool_handler = hackney_pool,
  recv_timeout = ?RECV_TIMEOUT,
  follow_redirect = false,
  max_redirect = 5,
  force_redirect = false,
  retries = 0,
  redirect = nil,
  location=nil,
  parser=nil,
  headers=hackney_headers_new:new(),
  state,
  response_state = start,
  mp_boundary = nil,
  req_type = normal,
  expect = false,
  async = false,
  with_body = false,
  max_body,
  stream_to,
  send_fun=nil,
  body_state=waiting,
  multipart=nil,
  req_chunk_size=4096,
  buffer = <<>>,
  partial_headers = [],
  version,
  clen = nil,
  te = nil,
  connection = nil,
  method = nil,
  path,
  ctype = nil
}).
oubiwann commented 1 year ago

Done.