Object built-in object

Object HttpResponse

http Response message object

Inheritance

#lineWidth: 1.5 #font: Helvetica,sans-Serif #fontSize: 10 #leading: 1.6 #.this: fill=lightgray #.class: fill=white [<class>object|toString();toJSON()] [<class>Message|new Message()|TEXT;BINARY|value;params;type;data;body;length;stream;lastError|read();readAll();write();json();pack();end();isEnded();clear();sendTo();readFrom()] [<class>HttpMessage|protocol;headers;keepAlive;upgrade;maxHeadersCount;maxBodySize;socket|hasHeader();firstHeader();allHeader();addHeader();setHeader();removeHeader()] [<this>HttpResponse|new HttpResponse()|statusCode;statusMessage;cookies|writeHead();addCookie();redirect();sendHeader()] [object] <:- [Message] [Message] <:- [HttpMessage] [HttpMessage] <:- [HttpResponse] Message new Message() TEXT BINARY value params type data body length stream lastError read() readAll() write() json() pack() end() isEnded() clear() sendTo() readFrom() HttpResponse new HttpResponse() statusCode statusMessage cookies writeHead() addCookie() redirect() sendHeader() HttpMessage protocol headers keepAlive upgrade maxHeadersCount maxBodySize socket hasHeader() firstHeader() allHeader() addHeader() setHeader() removeHeader() object toString() toJSON()

Constructor

HttpResponse

HttpResponse constructor to create a new HttpResponse object

1
new HttpResponse();

constant

TEXT

Specify message type 1, which represents a text type

1
const HttpResponse.TEXT = 1;

BINARY

Specify message type 2, which represents a binary type

1
const HttpResponse.BINARY = 2;

Member attributes

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 current message HttpCookie Object list

1
readonly NArray HttpResponse.cookies;

protocol

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

1
String HttpResponse.protocol;

headers

HttpCollection, Included in the message http The container of the message header, read-only attribute

1
readonly HttpCollection HttpResponse.headers;

keepAlive

Boolean, query and set whether to keep the connection

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 size of the body, 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 the data of the message, this attribute will return different data according to the content-type, when it is text, it returns the text, which is json When returning json, Other times return to binary

1
readonly Value HttpResponse.data;

body

SeekableStream, The stream object that contains the data part of the message

1
SeekableStream HttpResponse.body;

length

Long, the length of the data part of the message

1
readonly Long HttpResponse.length;

stream

Stream, Query the stream object when the message readFrom

1
readonly Stream HttpResponse.stream;

lastError

String, query and set the last error of message processing

1
String HttpResponse.lastError;

Member function

writeHead

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

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

Call parameters:

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

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

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

Call parameters:

  • statusCode: Integer, specify the return status of the response message
  • headers: Object, specify the response header added to the response message

addCookie

Add one to cookies HttpCookie Object

1
HttpResponse.addCookie(HttpCookie cookie);

Call parameters:


redirect

Send redirect to client

1
HttpResponse.redirect(String url);

Call parameters:

  • url: String, redirected address

Send redirect to client

1 2
HttpResponse.redirect(Integer statusCode, String url);

Call parameters:

  • statusCode: Integer, specify the return status of the response message, the accepted status is: 301, 302, 307
  • url: String, redirected address

sendHeader

Send formatting only http Head 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 whether there is a message header with the specified key value

1
Boolean HttpResponse.hasHeader(String name);

Call parameters:

  • name: String, specify the key value to be checked

Return result:

  • Boolean, Returns whether the key value exists

firstHeader

Query the first message header of the specified key value

1
String HttpResponse.firstHeader(String name);

Call parameters:

  • name: String, specify the key value to be queried

Return result:

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

allHeader

Query all message headers of the specified key value

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, if the data does not exist, returns null

addHeader

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

1
HttpResponse.addHeader(Object map);

Call parameters:

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

Add a set of message headers with a specified name, adding data does not modify the message headers of the existing key value

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

Call parameters:

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

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

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

Call parameters:

  • name: String, specify the key value to be added
  • 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 with the same key value

1
HttpResponse.setHeader(Object map);

Call parameters:

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

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

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

Call parameters:

  • name: String, specify the key value 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 with the same key value

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

Call parameters:

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

removeHeader

Delete all message headers of the specified key value

1
HttpResponse.removeHeader(String name);

Call parameters:

  • name: String, specify the key value to be deleted

read

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

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

Call parameters:

  • bytes: Integer, specify the amount of data to be read, the default is to read a random size data block, the size of the data read depends on the device

Return result:

  • Buffer, Return the data read from the stream, if there is no data to read, or the connection is interrupted, then return null

readAll

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

1
Buffer HttpResponse.readAll() async;

Return result:

  • Buffer, Return the data read from the stream, if there is no data to read, or the connection is interrupted, then return null

write

Write the given data, this method is the alias of 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 will not return data

Parse the data in the message in JSON encoding

1
Value HttpResponse.json();

Return result:

  • Value, Return the parsed result

pack

by msgpack Encode to write the given data

1
Value HttpResponse.pack(Value data);

Call parameters:

  • data: Value, given the data to be written

Return result:

  • Value, This method will not return data

by msgpack Encoding and parsing the data in the message

1
Value HttpResponse.pack();

Return result:

  • Value, Return the parsed result

end

Set the end of the current message processing,Chain The processor does not continue subsequent transactions

1
HttpResponse.end();

isEnded

Query whether 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 a formatted message 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 filling object

1
HttpResponse.readFrom(Stream stm) async;

Call parameters:

  • stm: Stream, Specify the stream object for reading formatted messages

toString

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

1
String HttpResponse.toString();

Return result:

  • String, Returns the 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