Module basic module

Module http

Hypertext Transfer Protocol module to support http protocol processing, module alias: https

Object

Request

Create an http request object, see HttpRequest

1
HttpRequest http.Request;

Response

Create an http response object, see HttpResponse

1
HttpResponse http.Response;

Create an http cookie object, see HttpCookie

1
HttpCookie http.Cookie;

Server

Create an http server, see HttpServer

1
HttpServer http.Server;

Client

Create an http client, see HttpClient

1
HttpClient http.Client;

HttpsServer

Create an https server, see HttpsServer

1
HttpsServer http.HttpsServer;

Handler

Create an http protocol handler object, see HttpHandler

1
HttpHandler http.Handler;

Repeater

Create an http request forwarding processor object, see HttpRepeater

1
HttpRepeater http.Repeater;

Static function

fileHandler

Create an http static file processor 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 catalog files, the default is false, not supported

Return result:

  • Handler , returns a static file handler for processing 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, so as to avoid 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 , X509Cert certificate, used for client authentication server
  • key : PKey , PKey private key, used to talk to the client

request

Send 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:


Request the specified url and return the result

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

Call parameters:

  • method : String, specify http request method: GET, POST, etc.
  • url : String, the specified url , must be the complete url including the host
  • opts : Object, specify additional information

Return result:

opts contains additional options requested, and the supported content is as follows:

1 2 3 4 5 6
{ "query": {}, "body": SeekedStream | Buffer | String | {}, "json": {}, "headers": {} }

The body and json must not appear at the same time. The default is {} without any additional information


get

Use the GET method to request the specified url and return the result, which is equivalent to request("GET", ...)

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

Call parameters:

  • url : String, the specified url , must be the complete url including the host
  • opts : Object, specify additional information

Return result:

opts contains additional options requested, and the supported content is as follows:

1 2 3 4 5 6
{ "query": {}, "body": SeekedStream | Buffer | String | {}, "json": {}, "headers": {} }

The body and json must not appear at the same time. The default is {} without any additional information


post

Use the POST method to request the specified url 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, the specified url , must be the complete url including the host
  • opts : Object, specify additional information

Return result:

opts contains additional options requested, and the supported content is as follows:

1 2 3 4 5 6
{ "query": {}, "body": SeekedStream | Buffer | String | {}, "json": {}, "headers": {} }

The body and json must not appear at the same time. The default is {} without any additional information


del

Use the DELETE method to request the specified url and return the result, which is equivalent to request("DELETE", ...)

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

Call parameters:

  • url : String, the specified url , must be the complete url including the host
  • opts : Object, specify additional information

Return result:

opts contains additional options requested, and the supported content is as follows:

1 2 3 4 5 6
{ "query": {}, "body": SeekedStream | Buffer | String | {}, "json": {}, "headers": {} }

The body and json must not appear at the same time. The default is {} without any additional information


put

Use the PUT method to request the specified url and return the result, which is equivalent to request("PUT", ...)

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

Call parameters:

  • url : String, the specified url , must be the complete url including the host
  • opts : Object, specify additional information

Return result:

opts contains additional options requested, and the supported content is as follows:

1 2 3 4 5 6
{ "query": {}, "body": SeekedStream | Buffer | String | {}, "json": {}, "headers": {} }

The body and json must not appear at the same time. The default is {} without any additional information


patch

Use the PATCH method to request the specified url and return the result, which is equivalent to request("PATCH", ...)

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

Call parameters:

  • url : String, the specified url , must be the complete url including the host
  • opts : Object, specify additional information

Return result:

opts contains additional options requested, and the supported content is as follows:

1 2 3 4 5 6
{ "query": {}, "body": SeekedStream | Buffer | String | {}, "json": {}, "headers": {} }

The body and json must not appear at the same time. The default is {} without any additional information

Static properties

STATUS_CODES

Array, returns a collection of standard HTTP response status codes, and a brief description of each.

1
static readonly Array http.STATUS_CODES;

cookies

NArray, returns a list of HttpCookie objects of the http client

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, and the size is not limited

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 keep-alive cache connections, the default is 128

1
static Integer http.poolSize;

poolTimeout

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

1
static Integer http.poolTimeout;

proxyAgent

String, query and set proxy server

1
static String http.proxyAgent;