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:
- Add a key-value data. Adding data does not modify the existing key-value data.
add
1
2
3
4headers.add({
'Content-Type': 'text/plain',
'User-Agent': 'fibjs'
});
- 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
4headers.add('Set-Cookie', [
'a=10',
'b=20'
]);
- Add a key-value data. Adding data does not modify the existing key-value data.
add
1headers.add('Accept-Encoding', 'gzip');
HttpCollection The form of setting data is the same as adding, and the method used is set
.
We can use has
to check whether the data with the specified key value exists in the container
1const contentTypeExists = headers.has('Content-Type');
Use to first
get the first value corresponding to a key in the container:
1const contentType = headers.first('Content-Type');
Use all
to 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
2const cookieArray = headers.all('Set-Cookie');
const alls = headers.all();
Use delete
the method to delete all data of the specified key value and return true
the representation
inheritance relationship
Operator
operator[String]
Allows direct access to values using key-value subscripts
1Variant HttpCollection[String];
member function
clear
Clear container data
1HttpCollection.clear();
has
Check whether the data with the specified key value exists in the container
1Boolean 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
1Variant 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
1Variant 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
1NObject 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.
1HttpCollection.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
2HttpCollection.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
2HttpCollection.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.
1HttpCollection.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
2HttpCollection.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
2HttpCollection.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
1HttpCollection.remove(String name);
Call parameters:
- name: String, specifies the key value to be deleted
delete
Delete all values of the specified key
1HttpCollection.delete(String name);
Call parameters:
- name: String, specifies the key value to be deleted
sort
Sort the contents of a container by key value
1HttpCollection.sort();
keys
Query the key value in the container
1NArray HttpCollection.keys();
Return results:
- NArray, returns an array containing all key values
values
Query the value in the container
1NArray 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.
1String 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.
1Value HttpCollection.toJSON(String key = "");
Call parameters:
- key: String, not used
Return results:
- Value, returns a value containing JSON serializable