Object built-in object

Object HttpResponse

http response message object

Inheritance

Constructor

HttpResponse

HttpResponse constructor to create a new HttpResponse object

1
new HttpResponse();

constant

TEXT

Specify message type 1, representing a text type

1
const HttpResponse.TEXT = 1;

BINARY

Specify message type 2, representing a binary type

1
const HttpResponse.BINARY = 2;

Member attribute

statusCode

Integer, query and set the return status of the response message

1
Integer HttpResponse.statusCode;

statusMessage

String, query and set the return message of the response message

1
String HttpResponse.statusMessage;

cookies

NArray, returns the list of HttpCookie objects

1
readonly NArray HttpResponse.cookies;

protocol

String, protocol version information, the allowed format is: HTTP/#.#

1
String HttpResponse.protocol;

headers

HttpCollection , the container that contains the http header in the message, read-only attribute

1
readonly HttpCollection HttpResponse.headers;

keepAlive

Boolean, query and set whether to stay connected

1
Boolean HttpResponse.keepAlive;

upgrade

Boolean, query and set whether it is an upgrade agreement

1
Boolean HttpResponse.upgrade;

maxHeadersCount

Integer, query and set the maximum number of request headers, the default is 128

1
Integer HttpResponse.maxHeadersCount;

maxBodySize

Integer, query and set the maximum body size, in MB, the default is 64

1
Integer HttpResponse.maxBodySize;

socket

Stream , query the source socket of the current object

1
readonly Stream HttpResponse.socket;

value

String, the basic content of the message

1
String HttpResponse.value;

params

NArray, the basic parameters of the message

1
readonly NArray HttpResponse.params;

type

Integer, message type

1
Integer HttpResponse.type;

data

Value, query message data

1
readonly Value HttpResponse.data;

body

SeekableStream , a stream object containing the message data part

1
SeekableStream HttpResponse.body;

length

Long, the length of the message data part

1
readonly Long HttpResponse.length;

stream

Stream , the stream object when querying the message readFrom

1
readonly Stream HttpResponse.stream;

lastError

String, the last error of querying and setting message processing

1
String HttpResponse.lastError;

Member function

writeHead

Set the return status of the response message, return the message, and add a response header

1 2 3
HttpResponse.writeHead(Integer statusCode, String statusMessage, Object headers = {});

Call parameters:

  • statusCode : Integer, specifies the return status of the response message
  • statusMessage : String, specifies the return message of the response message
  • headers : Object, specify the response headers added in the response message

Set the return status of the response message, return the message, and add a response header

1 2
HttpResponse.writeHead(Integer statusCode, Object headers = {});

Call parameters:

  • statusCode : Integer, specifies the return status of the response message
  • headers : Object, specify the response headers added in the response message

addCookie

Add an HttpCookie object to cookies

1
HttpResponse.addCookie(HttpCookie cookie);

Call parameters:


redirect

Send a redirect to the client

1
HttpResponse.redirect(String url);

Call parameters:

  • url : String, redirected address

sendHeader

Only send formatted http header to the given stream object

1
HttpResponse.sendHeader(Stream stm) async;

Call parameters:

  • stm : Stream , specify the stream object to receive formatted messages

hasHeader

Check if there is a message header for the specified key

1
Boolean HttpResponse.hasHeader(String name);

Call parameters:

  • name : String, specify the key to check

Return result:

  • Boolean , returns whether the key value exists

firstHeader

Query the first message header of the specified key

1
String HttpResponse.firstHeader(String name);

Call parameters:

  • name : String, specify the key to query

Return result:

  • String , returns the value corresponding to the key value, or undefined if it does not exist

allHeader

Query all message headers of the specified key

1
NObject HttpResponse.allHeader(String name = "");

Call parameters:

  • name : String, specify the key value to be queried, pass an empty string to return the result of all key values

Return result:

  • NObject , returns an array of all values ​​corresponding to the key value, or null if the data does not exist

addHeader

Add a message header, adding data does not modify the message header of the existing key

1
HttpResponse.addHeader(Object map);

Call parameters:

  • map : Object, specifies the key-value data dictionary to be added

Add a set of message headers with the specified name, add data without modifying the existing header of the key value

1 2
HttpResponse.addHeader(String name, Array values);

Call parameters:

  • name : String, specify the key to add
  • values : Array, specifies a set of data to be added

Add a message header, adding data does not modify the message header of the existing key

1 2
HttpResponse.addHeader(String name, String value);

Call parameters:

  • name : String, specify the key to add
  • value : String, specify the data to be added

setHeader

Set a message header, the setting data will modify the first value corresponding to the key value, and clear the remaining message headers of the same key value

1
HttpResponse.setHeader(Object map);

Call parameters:

  • map : Object, specifies the key-value data dictionary to be set

Set a group of message headers with the specified name, the setting data will modify the value corresponding to the key value, and clear the remaining message headers of the same key value

1 2
HttpResponse.setHeader(String name, Array values);

Call parameters:

  • name : String, specify the key to be set
  • values : Array, specify a set of data to be set

Set a message header, the setting data will modify the first value corresponding to the key value, and clear the remaining message headers of the same key value

1 2
HttpResponse.setHeader(String name, String value);

Call parameters:

  • name : String, specify the key to be set
  • value : String, specify the data to be set

removeHeader

Delete all message headers for the specified key

1
HttpResponse.removeHeader(String name);

Call parameters:

  • name : String, specify the key to delete

read

Read the data of the specified size from the stream, this method is an alias for the corresponding method of body

1
Buffer HttpResponse.read(Integer bytes = -1) async;

Call parameters:

  • bytes : Integer, specifies the amount of data to be read, the default is to read data blocks of random size, the size of the data read depends on the device

Return result:

  • Buffer , returns the data read from the stream, or null if no data is readable, or the connection is interrupted

readAll

Read all the remaining data from the stream, this method is an alias for the corresponding method of body

1
Buffer HttpResponse.readAll() async;

Return result:

  • Buffer , returns the data read from the stream, or null if no data is readable, or the connection is interrupted

write

Write the given data, this method is an alias for the corresponding method of body

1
HttpResponse.write(Buffer data) async;

Call parameters:

  • data : Buffer , given the data to be written

json

Write the given data in JSON encoding

1
Value HttpResponse.json(Value data);

Call parameters:

  • data : Value, given the data to be written

Return result:

  • Value , this method does not return data

Parse the data in the message in JSON encoding

1
Value HttpResponse.json();

Return result:

  • Value , return the parsed result

end

Set the current message processing to end, the Chain processor will not continue the subsequent transaction

1
HttpResponse.end();

isEnded

Check if the current message is over

1
Boolean HttpResponse.isEnded();

Return result:

  • Boolean , return true at the end

clear

Clear the content of the message

1
HttpResponse.clear();

sendTo

Send formatted messages to the given stream object

1
HttpResponse.sendTo(Stream stm) async;

Call parameters:

  • stm : Stream , specify the stream object to receive formatted messages

readFrom

Read the formatted message from the given cache stream object and parse the fill object

1
HttpResponse.readFrom(Stream stm) async;

Call parameters:

  • stm : Stream , specify a stream object to read formatted messages

toString

Returns the string representation of the object, generally returns "[Native Object]", the object can be reimplemented according to its own characteristics

1
String HttpResponse.toString();

Return result:

  • String , returns a string representation of the object

toJSON

Returns the JSON format representation of the object, generally returns a collection of readable attributes defined by the object

1
Value HttpResponse.toJSON(String key = "");

Call parameters:

  • key : String, unused

Return result:

  • Value , returns a value containing JSON serializable