Pipes

Interface

wptserve.pipes.gzip(request, response)

This pipe gzip-encodes response data.

It sets (or overwrites) these HTTP headers: Content-Encoding is set to gzip Content-Length is set to the length of the compressed content

wptserve.pipes.header(request, response, name, value, append=False)

Set a HTTP header.

Replaces any existing HTTP header of the same name unless append is set, in which case the header is appended without replacement.

Parameters:
  • name – Name of the header to set.

  • value – Value to use for the header.

  • append – True if existing headers should not be replaced

wptserve.pipes.slice(request, response, start, end=None)

Send a byte range of the response body

Parameters:
  • start – The starting offset. Follows python semantics including negative numbers.

  • end – The ending offset, again with python semantics and None (spelled “null” in a query string) to indicate the end of the file.

wptserve.pipes.status(request, response, code)

Alter the status code.

Parameters:

code – Status code to use for the response.

wptserve.pipes.sub(request, response, escape_type='html')

Substitute environment information about the server and request into the script.

Parameters:

escape_type – String detailing the type of escaping to use. Known values are “html” and “none”, with “html” the default for historic reasons.

The format is a very limited template language. Substitutions are enclosed by {{ and }}. There are several available substitutions:

host

A simple string value and represents the primary host from which the tests are being run.

domains

A dictionary of available domains indexed by subdomain name.

ports

A dictionary of lists of ports indexed by protocol.

location

A dictionary of parts of the request URL. Valid keys are ‘server, ‘scheme’, ‘host’, ‘hostname’, ‘port’, ‘path’ and ‘query’. ‘server’ is scheme://host:port, ‘host’ is hostname:port, and query includes the leading ‘?’, but other delimiters are omitted.

headers

A dictionary of HTTP headers in the request.

header_or_default(header, default)

The value of an HTTP header, or a default value if it is absent. For example:

{{header_or_default(X-Test, test-header-absent)}}
GET

A dictionary of query parameters supplied with the request.

uuid()

A pesudo-random UUID suitable for usage with stash

file_hash(algorithm, filepath)

The cryptographic hash of a file. Supported algorithms: md5, sha1, sha224, sha256, sha384, and sha512. For example:

{{file_hash(md5, dom/interfaces.html)}}
fs_path(filepath)

The absolute path to a file inside the wpt document root

So for example in a setup running on localhost with a www subdomain and a http server on ports 80 and 81:

{{host}} => localhost
{{domains[www]}} => www.localhost
{{ports[http][1]}} => 81

It is also possible to assign a value to a variable name, which must start with the $ character, using the “:” syntax e.g.:

{{$id:uuid()}}

Later substitutions in the same file may then refer to the variable by name e.g.:

{{$id}}
wptserve.pipes.trickle(request, response, delays)

Send the response in parts, with time delays.

Parameters:

delays

A string of delays and amounts, in bytes, of the response to send. Each component is separated by a colon. Amounts in bytes are plain integers, whilst delays are floats prefixed with a single d e.g. d1:100:d2 Would cause a 1 second delay, would then send 100 bytes of the file, and then cause a 2 second delay, before sending the remainder of the file.

If the last token is of the form rN, instead of sending the remainder of the file, the previous N instructions will be repeated until the whole file has been sent e.g. d1:100:d2:r2 Causes a delay of 1s, then 100 bytes to be sent, then a 2s delay and then a further 100 bytes followed by a two second delay until the response has been fully sent.