This module provides a class to create a set of HTTP headers.
The class' API is pretty similar to native the Headers class
but has some extra functionality and doesn't implement the Guard conceptions.
Because, the core/request module can use different engines, but not only fetch or XMLHttpRequest.
These engines can have different peculiarities, so we need to create a new abstraction.
There is a possibility to provide initial headers while creating a new Headers instance.
These headers can be provided using a simple dictionary when keys are header names and values are header values.
The value can be defined as a string or list of strings - all values will be joined into one string with a comma separator.
The class supports a feature when headers' keys or values link to extra values from request data.
To do this, place within header key or value one or more template directives. Let's see the example below.
// Notice, after applying values to templates, all used values are marked as non-enumerable console.log(query.propertyIsEnumerable('type')); // false console.log(query.propertyIsEnumerable('typeValue')); // false
core/request/headers
This module provides a class to create a set of HTTP headers. The class' API is pretty similar to native the Headers class but has some extra functionality and doesn't implement the Guard conceptions.
Why not just use the native Headers class?
Because, the
core/request
module can use different engines, but not onlyfetch
orXMLHttpRequest
. These engines can have different peculiarities, so we need to create a new abstraction.Initial headers
There is a possibility to provide initial headers while creating a new Headers instance. These headers can be provided using a simple dictionary when keys are header names and values are header values. The value can be defined as a string or list of strings - all values will be joined into one string with a comma separator.
Also, initial headers can be provided via another Headers instance or native browser Headers instance.
Or, you can pass a string with raw HTTP headers.
Interpolation of headers' keys and values
The class supports a feature when headers' keys or values link to extra values from request data. To do this, place within header key or value one or more template directives. Let's see the example below.
Headers' instance as a simple dictionary
For backward compatibility with previous versions of V4Fire, the instance of the Headers class can be used as a simple dictionary.
To make headers read-only, use
Object.freeze
.