-
Notifications
You must be signed in to change notification settings - Fork 64
/
HTTP.txt
208 lines (157 loc) · 5.86 KB
/
HTTP.txt
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
*vital/Web/HTTP.txt* simple HTTP client library.
Maintainer: mattn <[email protected]>
thinca <[email protected]>
==============================================================================
CONTENTS *Vital.Web.HTTP-contents*
INTRODUCTION |Vital.Web.HTTP-introduction|
INTERFACE |Vital.Web.HTTP-interface|
Functions |Vital.Web.HTTP-functions|
Response |Vital.Web.HTTP-response|
==============================================================================
INTRODUCTION *Vital.Web.HTTP-introduction*
*Vital.Web.HTTP* is an HTTP Utilities Library. It provides a simple HTTP
client.
==============================================================================
INTERFACE *Vital.Web.HTTP-interface*
------------------------------------------------------------------------------
FUNCTIONS *Vital.Web.HTTP-functions*
get({url} [, {param} [, {header}]]) *Vital.Web.HTTP.get()*
Send a GET request to the server.
This is just a wrapper of |Vital.Web.HTTP.request()|.
post({url} [, {param} [, {header}]]) *Vital.Web.HTTP.post()*
Send a POST request to the server.
This is just a wrapper of |Vital.Web.HTTP.request()|.
request({settings}) *Vital.Web.HTTP.request()*
request({url} [, {settings}])
request({method}, {url} [, {settings}])
Send a request to the server.
This function requires one of the clients, "curl" or "wget".
{settings} is a |Dictionary| which contains the following items:
"url" Required
URL of a server.
"method" Default: "GET"
HTTP Method, such as GET, HEAD, POST, PUT, DELETE, or PATCH.
"param" Default: (None)
GET parameters. This is a string or a dictionary.
If dictionary, it is converted to a string by
|Vital.Web.HTTP.encodeURI()|.
This is appended to url.
"data" Default: (None)
POST data. This is a string, a list, or a dictionary.
If it is a dictionary, it is converted to a string by
|Vital.Web.HTTP.encodeURI()|.
"headers" Default: (None)
Request headers. This is a dictionary.
"contentType" Default: (None)
Content-Type for "data".
This is one of "headers". This is used preferentially.
"outputFile" Default: (None)
Output the result to this file.
"content" of the result become empty when this is specified.
"timeout" Default: (None)
Network timeout by seconds.
"username" Default: (None)
User name for an HTTP authentication.
"password" Default: (None)
Password for an HTTP authentication.
"bearerToken" Default: (None)
Bearer token for an HTTP authentication (OAuth2).
"maxRedirect" Default: 20
Maximum number of redirections.
The default is 20, which is usually far more than necessary.
"retry" Default: 1
Maximum number of retries.
"client" Default: ["python", "curl", "wget",
"python3", "python2"]
Candidate list of HTTP client to use for a request.
The first available one is used.
A string as an HTTP client is also possible.
See also |Vital.Web.HTTP-client|.
"command"
Command name for a client. You should use with "client".
This is a |Dictionary| that has client name as key and has the
command as value.
This maybe becomes like the following. >
{
"curl": "/usr/bin/curl",
"wget": "/usr/local/bin/wget",
}
<
"authMethod" Default: (None)
(This is only valid for "curl" interface.)
Specify the authorization method.
The value must be in ['basic', 'digest', 'ntlm', 'negotiate',
'oauth2']
The default value is None, and then use "anyauth".
"gzipDecompress" Default: 0
Attempt to decompress response data as if it was gzipped
"unixSocket" Default: (None)
Use --unix-sokect (only curl >= 7.40.0)
parseHeader({headers}) *Vital.Web.HTTP.parseHeader()*
Parse {headers} list to a dictionary.
Duplicated fields are overwritten.
encodeURI({param}) *Vital.Web.HTTP.encodeURI()*
Encode params as URI query.
decodeURI({str}) *Vital.Web.HTTP.decodeURI()*
Decode string as URI params.
encodeURIComponent({str}) *Vital.Web.HTTP.encodeURIComponent()*
Encode param as URI components.
------------------------------------------------------------------------------
RESPONSE *Vital.Web.HTTP-response*
|Vital.Web.HTTP.request()|, |Vital.Web.HTTP.get()|, and |Vital.Web.HTTP.post()|
return data structure as |Directory| like following.
>
{
"header": [
"Content-Type: text/html",
"Content-Length: 310"
],
"allHeaders": [
"Set-Cookie: k1=v1; Path=/",
"Content-Type: text/html",
"Content-Length: 310"
],
"content": "<html> .....",
"status": 200,
"statusText": "OK",
"success": 1,
"redirectInfo": [],
}
<
"header"
The header lines of a response. This can convert to
|Dictionary| by |Vital.Web.HTTP.parseHeader()|.
"allHeaders"
All of header lines that includes redirectInfo.
"content"
The content of a response.
"status"
The http status code of a response.
If the code couldn't take, this is 0.
"statusText"
The http status code text of a response.
If the code couldn't take, this is the empty string.
"success"
This is 1 if the "status" is 2xx.
"redirectInfo"
When the request was redirected, the redirected responses are
stored. Form of these are the same as a response.
------------------------------------------------------------------------------
CLIENT *Vital.Web.HTTP-client*
The following can be used.
(TODO: More document. Especially about limitation.)
python *Vital.Web.HTTP-client-python*
"python" as "python3" or "python2" auto select.
(High priority for "python3".)
curl *Vital.Web.HTTP-client-curl*
Use curl command.
http://curl.haxx.se/
wget *Vital.Web.HTTP-client-wget*
Use wget command.
http://www.gnu.org/software/wget/
python3 *Vital.Web.HTTP-client-python3*
Use Python3's urllib.request library via |if_pyth.txt|.
python2 *Vital.Web.HTTP-client-python2*
Use Python2's urllib2 library via |if_pyth.txt|.
==============================================================================
vim:tw=78:fo=tcq2mM:ts=8:ft=help:norl