1%%
2%% %CopyrightBegin%
3%%
4%% Copyright Ericsson AB 2005-2018. All Rights Reserved.
5%%
6%% Licensed under the Apache License, Version 2.0 (the "License");
7%% you may not use this file except in compliance with the License.
8%% You may obtain a copy of the License at
9%%
10%%     http://www.apache.org/licenses/LICENSE-2.0
11%%
12%% Unless required by applicable law or agreed to in writing, software
13%% distributed under the License is distributed on an "AS IS" BASIS,
14%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15%% See the License for the specific language governing permissions and
16%% limitations under the License.
17%%
18%% %CopyrightEnd%
19%%
20%%
21
22-ifndef(httpc_internal_hrl).
23-define(httpc_internal_hrl, true).
24
25-include_lib("inets/src/inets_app/inets_internal.hrl").
26
27-define(SERVICE, httpc).
28-define(hcri(Label, Data), ?report_important(Label, ?SERVICE, Data)).
29-define(hcrv(Label, Data), ?report_verbose(Label,   ?SERVICE, Data)).
30-define(hcrd(Label, Data), ?report_debug(Label,     ?SERVICE, Data)).
31-define(hcrt(Label, Data), ?report_trace(Label,     ?SERVICE, Data)).
32
33-define(HTTP_REQUEST_TIMEOUT,    infinity).
34-define(HTTP_REQUEST_CTIMEOUT,   ?HTTP_REQUEST_TIMEOUT).
35-define(HTTP_PIPELINE_TIMEOUT,   0).
36-define(HTTP_PIPELINE_LENGTH,    2).
37-define(HTTP_MAX_TCP_SESSIONS,   2).
38-define(HTTP_MAX_REDIRECTS,      4).
39-define(HTTP_KEEP_ALIVE_TIMEOUT, 120000).
40-define(HTTP_KEEP_ALIVE_LENGTH,  5).
41-define(TLS_UPGRADE_TOKEN, "TLS/1.0").
42
43%%% HTTP Client per request settings
44-record(http_options,
45	{
46	  %% "HTTP/1.1" | "HTTP/1.0" | "HTTP/0.9"
47	  version :: 'undefined' | string(),
48
49	  %% ms before a request times out
50	  timeout = ?HTTP_REQUEST_TIMEOUT :: timeout(),
51
52	  %% true if auto redirect on 30x response
53	  autoredirect = true :: boolean(),
54
55	  %% ssl socket options
56	  ssl = [],
57
58	  %% {User, Password} = {string(), string()}
59	  proxy_auth,
60
61	  %% true if not strictly std compliant
62	  relaxed = false :: boolean(),
63
64	  %% integer() - ms before a connect times out
65	  connect_timeout = ?HTTP_REQUEST_CTIMEOUT :: timeout(),
66
67	  %% Use %-encoding rfc 2396
68	  url_encode :: 'undefined' | boolean()
69	 }
70       ).
71-type http_options() :: #http_options{}.
72
73%%% HTTP Client per profile setting.
74-record(options,
75	{
76	 proxy = {undefined, []}, % {{ProxyHost, ProxyPort}, [NoProxy]},
77	 https_proxy = {undefined, []}, % {{ProxyHost, ProxyPort}, [NoProxy]}
78	 %% 0 means persistent connections are used without pipelining
79	 pipeline_timeout      = ?HTTP_PIPELINE_TIMEOUT,
80	 max_pipeline_length   = ?HTTP_PIPELINE_LENGTH,
81	 max_keep_alive_length = ?HTTP_KEEP_ALIVE_LENGTH,
82	 keep_alive_timeout    = ?HTTP_KEEP_ALIVE_TIMEOUT, % Used when pipeline_timeout = 0
83	 max_sessions          = ?HTTP_MAX_TCP_SESSIONS,
84	 cookies               = disabled, % enabled | disabled | verify
85	 verbose               = false,   % boolean(),
86	 ipfamily              = inet,    % inet | inet6 | inet6fb4 | local
87	 ip                    = default, % specify local interface
88	 port                  = default, % specify local port
89	 socket_opts           = [],      % other socket options
90	 unix_socket           = undefined % Local unix socket
91	}
92       ).
93-type options() :: #options{}.
94
95%%% All data associated to a specific HTTP request
96-record(request,
97	{
98	  id            :: 'undefined' | reference(), % Request Id
99	  from,          % pid() - Caller
100	  redircount = 0,% Number of redirects made for this request
101	  scheme,        % http | https
102	  address,       % ({Host,Port}) Destination Host and Port
103	  path,          % string() - Path of parsed URL
104	  pquery,        % string() - Rest of parsed URL
105	  method,        % atom() - HTTP request Method
106	  headers,       % #http_request_h{}
107	  content,       % {ContentType, Body} - Current HTTP request
108	  settings      :: http_options(), % User defined settings
109	  abs_uri,       % string() ex: "http://www.erlang.org"
110	  userinfo,      % string() - optinal "<userinfo>@<host>:<port>"
111	  stream,	 % boolean() - stream async reply?
112	  headers_as_is, % boolean() - workaround for servers that does
113			 % not honor the http standard, can also be used
114			 % for testing purposes.
115	  started,       % integer() > 0 - When we started processing the
116			 % request
117	  timer         :: undefined | reference(),
118	  socket_opts,   % undefined | [socket_option()]
119	  unix_socket,   % undefined | string()
120	  ipv6_host_with_brackets % boolean()
121	}
122       ).
123-type request() :: #request{}.
124
125-record(session,
126	{
127	  %% {{Host, Port}, HandlerPid}
128	  id,
129
130	  client_close :: 'undefined' | boolean(),
131
132	  %% http (HTTP/TCP) | https (HTTP/SSL/TCP)
133	  scheme,
134
135	  %% Open socket, used by connection
136	  socket,
137
138	  %% socket-type, used by connection
139	  socket_type,
140
141	  %% Current length of pipeline or keep-alive queue
142	  queue_length = 1,
143
144	  %% pipeline | keep_alive (wait for response before sending new request)
145	  type :: 'undefined' | 'pipeline' | 'keep_alive',
146
147	  %% This will be true, when a response has been received for
148	  %% the first request. See type above.
149	  available = false :: boolean()
150	 }).
151-type session() :: #session{}.
152
153-record(http_cookie,
154	{
155	  domain,
156	  domain_default = false,
157	  name,
158	  value,
159	  comment,
160	  max_age = session,
161	  path,
162	  path_default = false,
163	  secure = false,
164	  version = "0"
165	 }).
166-type http_cookie() :: #http_cookie{}.
167
168%% -record(parsed_uri,
169%% 	{
170%% 	  scheme, % http | https
171%% 	  uinfo,  % string()
172%% 	  host,   % string()
173%% 	  port,   % integer()
174%% 	  path,   % string()
175%% 	  q       % query: string()
176%% 	 }).
177
178
179-endif. % -ifdef(httpc_internal_hrl).
180