Module base module

module http

Hypertext transfer protocol module to support http protocol processing, module alias: https

object

Request

Create an http request object, seeHttpRequest

1
HttpRequest http.Request;

Response

Create an http response object, seeHttpResponse

1
HttpResponse http.Response;

Create an http cookie object, seeHttpCookie

1
HttpCookie http.Cookie;

Server

Create an http server, seeHttpServer

1
HttpServer http.Server;

Client

Create an http client, seeHttpClient

1
HttpClient http.Client;

HttpsServer

Create an https server, seeHttpsServer

1
HttpsServer http.HttpsServer;

Handler

Create an http protocol handler object, seeHttpHandler

1
HttpHandler http.Handler;

Repeater

Create an http request forwarding handler object, seeHttpRepeater

1
HttpRepeater http.Repeater;

static function

fileHandler

Create an http static file handler to respond to http messages with static files

1 2 3
static 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 2
static 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 2
static HttpResponse http.request(Stream conn, HttpRequest req) async;

Call parameters:

Return result:


Send an http request to the specified stream object and return the result

1 2 3
static HttpResponse http.request(Stream conn, HttpRequest req, SeekableStream response_body) async;

Call parameters:

Return result:


request specifiedurl, and return the result

1 2 3
static 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:

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 2
static HttpResponse http.get(String url, Object opts = {}) async;

Call parameters:

  • url: String, specifiedurl, must be the completeurl
  • opts: Object, specify additional information

Return result:

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 2
static HttpResponse http.post(String url, Object opts = {}) async;

Call parameters:

  • url: String, specifiedurl, must be the completeurl
  • opts: Object, specify additional information

Return result:

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 2
static HttpResponse http.del(String url, Object opts = {}) async;

Call parameters:

  • url: String, specifiedurl, must be the completeurl
  • opts: Object, specify additional information

Return result:

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 2
static HttpResponse http.put(String url, Object opts = {}) async;

Call parameters:

  • url: String, specifiedurl, must be the completeurl
  • opts: Object, specify additional information

Return result:

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 2
static HttpResponse http.patch(String url, Object opts = {}) async;

Call parameters:

  • url: String, specifiedurl, must be the completeurl
  • opts: Object, specify additional information

Return result:

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


Request the specified using the HEAD methodurl, and return the result, which is equivalent to request("HEAD", ...)

1 2
static HttpResponse http.head(String url, Object opts = {}) async;

Call parameters:

  • url: String, specifiedurl, must be the completeurl
  • opts: Object, specify additional information

Return result:

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.

1
static readonly Array http.STATUS_CODES;

cookies

NArray, returns the http client'sHttpCookieobject list

1
static readonly NArray http.cookies;

timeout

Integer, query and set timeout

1
static Integer http.timeout;

enableCookie

Boolean, cookie function switch, enabled by default

1
static Boolean http.enableCookie;

autoRedirect

Boolean, automatic redirect function switch, enabled by default

1
static Boolean http.autoRedirect;

enableEncoding

Boolean, automatic decompression function switch, enabled by default

1
static Boolean http.enableEncoding;

maxBodySize

Integer, query and set the maximum size of the body, in MB, the default is -1, no size limit

1
static Integer http.maxBodySize;

userAgent

String, query and set the browser ID in the http request

1
static String http.userAgent;

poolSize

Integer, query and set the maximum number of cached connections for keep-alive, default 128

1
static Integer http.poolSize;

poolTimeout

Integer, query and set keep-alive cache connection timeout, default 10000 ms

1
static Integer http.poolTimeout;

proxyAgent

String, query and set proxy server, support http/https/socks5 proxy

1
static String http.proxyAgent;