Object built-in object

ObjectHttpCollection

HttpCollection is a general container for processinghttpheaders, query, form, cookie data in the message

We take headers as an example to illustrate the use of HttpCollection.

HttpCollection supports three forms of adding data:

  1. Add a key-value data. Adding data does not modify the existing key-value data.add
1 2 3 4
headers.add({ 'Content-Type': 'text/plain', 'User-Agent': 'fibjs' });
  1. Add a set of data with a key value. Adding data does not modify the data of the existing key value.add
1 2 3 4
headers.add('Set-Cookie', [ 'a=10', 'b=20' ]);
  1. Add a key-value data. Adding data does not modify the existing key-value data.add
1
headers.add('Accept-Encoding', 'gzip');

HttpCollection The form of setting data is the same as adding, and the method used is set.

We can use hasto check whether the data with the specified key value exists in the container

1
const contentTypeExists = headers.has('Content-Type');

Use to firstget the first value corresponding to a key in the container:

1
const contentType = headers.first('Content-Type');

Use allto query all values ​​of the specified key value and return an array. If an empty string argument is passed, the full value is returned

1 2
const cookieArray = headers.all('Set-Cookie'); const alls = headers.all();

Use deletethe method to delete all data of the specified key value and return truethe representation

inheritance relationship

Operator

operator[String]

Allows direct access to values ​​using key-value subscripts

1
Variant HttpCollection[String];

member function

clear

Clear container data

1
HttpCollection.clear();

has

Check whether the data with the specified key value exists in the container

1
Boolean HttpCollection.has(String name);

Call parameters:

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

Return results:

  • Boolean, returns whether the key value exists

first

Query the first value of the specified key value

1
Variant HttpCollection.first(String name);

Call parameters:

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

Return results:

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

get

Query the first value of the specified key value, which is equivalent to first

1
Variant HttpCollection.get(String name);

Call parameters:

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

Return results:

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

all

Query all values ​​of the specified key value

1
NObject HttpCollection.all(String name = "");

Call parameters:

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

Return results:

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

add

Add a key-value data. Adding data does not modify the existing key-value data.

1
HttpCollection.add(Object map);

Call parameters:

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

Add a set of data for a key value. Adding data does not modify the data of the existing key value.

1 2
HttpCollection.add(String name, Array values);

Call parameters:

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

Add a key-value data. Adding data does not modify the existing key-value data.

1 2
HttpCollection.add(String name, Variant value);

Call parameters:

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

set

Set a key value data. Setting the data will modify the first value corresponding to the key value and clear the remaining data with the same key value.

1
HttpCollection.set(Object map);

Call parameters:

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

Set a set of data for a key value. Setting the data will modify the value corresponding to the key value and clear the remaining data with the same key value.

1 2
HttpCollection.set(String name, Array values);

Call parameters:

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

Set a key value data. Setting the data will modify the first value corresponding to the key value and clear the remaining data with the same key value.

1 2
HttpCollection.set(String name, Variant value);

Call parameters:

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

remove

Delete all values ​​of the specified key

1
HttpCollection.remove(String name);

Call parameters:

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

delete

Delete all values ​​of the specified key

1
HttpCollection.delete(String name);

Call parameters:

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

sort

Sort the contents of a container by key value

1
HttpCollection.sort();

keys

Query the key value in the container

1
NArray HttpCollection.keys();

Return results:

  • NArray, returns an array containing all key values

values

Query the value in the container

1
NArray HttpCollection.values();

Return results:

  • NArray, returns an array containing all values

toString

Returns the string representation of the object. Generally, "[Native Object]" is returned. The object can be re-implemented according to its own characteristics.

1
String HttpCollection.toString();

Return results:

  • String, returns the string representation of the object

toJSON

Returns a JSON format representation of the object, generally returning a collection of readable properties defined by the object.

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

Call parameters:

  • key: String, not used

Return results:

  • Value, returns a value containing JSON serializable