On this page:
4.1 Header Fields
4.2 Header Objects
header<%>
get-header-fields
get-header-lines
has-key?
get-values
get-value
get-integer-value
header-field-key?
8.12

4 Headers🔗ℹ

A request or response contains a single header, which consists of zero or more header fields. Each field has a name (or key) and a value.

4.1 Header Fields🔗ℹ

Requests use the following representation of headers: a header is a list of header fields. The user may supply header fields in the form described by in-header-field/c, but they are checked and converted into the form described by header-field/c.

4.2 Header Objects🔗ℹ

A header<%> instance contains a list of header fields and adds useful methods.

interface

header<%> : interface?

Interface for objects representing response headers and trailers.

method

(send a-header get-header-fields)  (listof header-field/c)

Gets a list of header fields, where each entry has the form (list key-bytes value-bytes). The ordering of different keys in the resulting list is not specified.

If a given key has multiple values, the result list has multiple entries for that key—that is, values are not combined. The result list preserves the order of values for a given key.

method

(send a-header get-header-lines)  (listof bytes?)

Gets a list of header field lines. The ordering of different keys in the resulting list is not specified.

If a given key has multiple values, the result list has multiple entries for that key—that is, values are not combined. The result list preserves the order of values for a given key.

method

(send a-header has-key? key)  boolean?

  key : header-field-key?
Returns #t if the header contains a field named key, #f otherwise.

method

(send a-header get-values key)  (or/c (listof bytes?) #f)

  key : header-field-key?
Returns the list of field values associated with key, or #f if the header does not contain a field named key.

The result list contains one element per field line in the original header. That is, this method does not perform splitting or combination of field values.

method

(send a-header get-value key)  (or/c bytes? #f)

  key : header-field-key?
Returns the value associated with key as a single byte string, or #f if the header does not contain a field named key.

If the original header contained multiple lines for key, the values are combined by concatenating them separated by #", ". Use get-values instead for fields that do not have comma-separable values, such as Set-Cookie.

method

(send a-header get-integer-value key)

  (or/c exact-integer? #f)
  key : header-field-key?
Returns the integer value associated with key. If key has no value, or if the value is not a single exact integer, returns #f instead.

procedure

(header-field-key? v)  boolean?

  v : any/c
Returns #t if v is a byte string that is a valid, canonical header field name, #f otherwise.

A valid header field name must match the grammar for token; in addition, it must not contain any upper-case letters.

Examples:
> (header-field-key? #"content-length")

#t

> (header-field-key? #"Content-Length")

#f