module http
Hypertext transfer protocol module to support http protocol processing, module alias: https
object
Request
Create an http request object, seeHttpRequest
1HttpRequest http.Request;
Response
Create an http response object, seeHttpResponse
1HttpResponse http.Response;
Cookie
Create an http cookie object, seeHttpCookie
1HttpCookie http.Cookie;
Server
Create an http server, seeHttpServer
1HttpServer http.Server;
Client
Create an http client, seeHttpClient
1HttpClient http.Client;
HttpsServer
Create an https server, seeHttpsServer
1HttpsServer http.HttpsServer;
Handler
Create an http protocol handler object, seeHttpHandler
1HttpHandler http.Handler;
Repeater
Create an http request forwarding handler object, seeHttpRepeater
1HttpRepeater http.Repeater;
static function
fileHandler
Create an http static file handler to respond to http messages with static files
1
2
3static Handler http.fileHandler(String root,
Object mimes = {},
Boolean autoIndex = false);
Call parameters:
- root: String, file root path
- mimes: Object, extended mime settings
- autoIndex: Boolean, whether to support browsing directory files, the default is false, not supported
Return result:
- Handler, returns a static file handler for handling http messages
fileHandler supports gzip pre-compression. When the request accepts gzip encoding and the filename.ext.gz file exists in the same path, it will directly return this file, thus avoiding the server load caused by repeated compression.
setClientCert
Set default client certificate
1
2static http.setClientCert(X509Cert crt,
PKey key);
Call parameters:
- crt:X509Cert, the certificate to send to the server to authenticate the client
- key:PKey, the private key used to talk to the client
request
Send an http request to the specified stream object and return the result
1
2static HttpResponse http.request(Stream conn,
HttpRequest req) async;
Call parameters:
- conn:Stream, specifies the stream object that handles the request
- req:HttpRequest, to be sentHttpRequestobject
Return result:
- HttpResponse, returns the server response
Send an http request to the specified stream object and return the result
1
2
3static HttpResponse http.request(Stream conn,
HttpRequest req,
SeekableStream response_body) async;
Call parameters:
- conn:Stream, specifies the stream object that handles the request
- req:HttpRequest, to be sentHttpRequestobject
- response_body:SeekableStream, specifying the flow of response.body
Return result:
- HttpResponse, returns the server response
request specifiedurl, and return the result
1
2
3static HttpResponse http.request(String method,
String url,
Object opts = {}) async;
Call parameters:
- method: String, specify the http request method: GET, POST, etc.
- url: String, specifiedurl, must be the completeurl
- opts: Object, specify additional information
Return result:
- HttpResponse, returns the server response
opts contains additional options for the request, the supported ones are as follows:
1
2
3
4
5
6
7
8
9{
"method": "GET", //指定 http 请求方法:GET, POST 等
"query": {},
"body": SeekableStream | Buffer | String | {},
"json": {},
"pack": {},
"headers": {},
"response_body": SeekableStream //指定接受 resposne 数据的流
}
where body,json, pack must not appear at the same time. Defaults to {}, does not contain any additional information
get
Use the GET method to request the specifiedurl, and return the result, equivalent to request("GET", ...)
1
2static HttpResponse http.get(String url,
Object opts = {}) async;
Call parameters:
Return result:
- HttpResponse, returns the server response
opts contains additional options for the request, the supported ones are as follows:
1
2
3
4
5
6
7
8{
"method": "GET", //指定 http 请求方法:GET, POST 等
"query": {},
"body": SeekableStream | Buffer | String | {},
"json": {},
"pack": {},
"headers": {}
}
where body,json, pack must not appear at the same time. Defaults to {}, does not contain any additional information
post
use the POST method to request the specifiedurl, and return the result, which is equivalent to request("POST", ...)
1
2static HttpResponse http.post(String url,
Object opts = {}) async;
Call parameters:
Return result:
- HttpResponse, returns the server response
opts contains additional options for the request, the supported ones are as follows:
1
2
3
4
5
6
7
8{
"method": "GET", //指定 http 请求方法:GET, POST 等
"query": {},
"body": SeekableStream | Buffer | String | {},
"json": {},
"pack": {},
"headers": {}
}
where body,json, pack must not appear at the same time. Defaults to {}, does not contain any additional information
del
Use the DELETE method to request the specifiedurl, and return the result, equivalent to request("DELETE", ...)
1
2static HttpResponse http.del(String url,
Object opts = {}) async;
Call parameters:
Return result:
- HttpResponse, returns the server response
opts contains additional options for the request, the supported ones are as follows:
1
2
3
4
5
6
7
8{
"method": "GET", //指定 http 请求方法:GET, POST 等
"query": {},
"body": SeekableStream | Buffer | String | {},
"json": {},
"pack": {},
"headers": {}
}
where body,json, pack must not appear at the same time. Defaults to {}, does not contain any additional information
put
Use the PUT method to request the specifiedurl, and return the result, equivalent to request("PUT", ...)
1
2static HttpResponse http.put(String url,
Object opts = {}) async;
Call parameters:
Return result:
- HttpResponse, returns the server response
opts contains additional options for the request, the supported ones are as follows:
1
2
3
4
5
6
7
8{
"method": "GET", //指定 http 请求方法:GET, POST 等
"query": {},
"body": SeekableStream | Buffer | String | {},
"json": {},
"pack": {},
"headers": {}
}
where body,json, pack must not appear at the same time. Defaults to {}, does not contain any additional information
patch
Use the PATCH method to request the specifiedurl, and return the result, equivalent to request("PATCH", ...)
1
2static HttpResponse http.patch(String url,
Object opts = {}) async;
Call parameters:
Return result:
- HttpResponse, returns the server response
opts contains additional options for the request, the supported ones are as follows:
1
2
3
4
5
6
7
8{
"method": "GET", //指定 http 请求方法:GET, POST 等
"query": {},
"body": SeekableStream | Buffer | String | {},
"json": {},
"pack": {},
"headers": {}
}
where body,json, pack must not appear at the same time. Defaults to {}, does not contain any additional information
head
Request the specified using the HEAD methodurl, and return the result, which is equivalent to request("HEAD", ...)
1
2static HttpResponse http.head(String url,
Object opts = {}) async;
Call parameters:
Return result:
- HttpResponse, returns the server response
opts contains additional options for the request, the supported ones are as follows:
1
2
3
4
5
6
7
8{
"method": "GET", //指定 http 请求方法:GET, POST 等
"query": {},
"body": SeekableStream | Buffer | String | {},
"json": {},
"pack": {},
"headers": {}
}
where body,json, pack must not appear at the same time. Defaults to {}, does not contain any additional information
static properties
STATUS_CODES
Array, returns a collection of standard HTTP response status codes, along with a short description of each.
1static readonly Array http.STATUS_CODES;
cookies
NArray, returns the http client'sHttpCookieobject list
1static readonly NArray http.cookies;
timeout
Integer, query and set timeout
1static Integer http.timeout;
enableCookie
Boolean, cookie function switch, enabled by default
1static Boolean http.enableCookie;
autoRedirect
Boolean, automatic redirect function switch, enabled by default
1static Boolean http.autoRedirect;
enableEncoding
Boolean, automatic decompression function switch, enabled by default
1static Boolean http.enableEncoding;
maxBodySize
Integer, query and set the maximum size of the body, in MB, the default is -1, no size limit
1static Integer http.maxBodySize;
userAgent
String, query and set the browser ID in the http request
1static String http.userAgent;
poolSize
Integer, query and set the maximum number of cached connections for keep-alive, default 128
1static Integer http.poolSize;
poolTimeout
Integer, query and set keep-alive cache connection timeout, default 10000 ms
1static Integer http.poolTimeout;
proxyAgent
String, query and set proxy server, support http/https/socks5 proxy
1static String http.proxyAgent;