Skip to content

selenium.grid.server.http

Server-side HTTP request and response primitives and the route dispatch seam.

Request

struct Request;

An inbound HTTP request as seen by the grid router.

method

string method;

The HTTP method, uppercase ("GET", "POST", "DELETE").

path

string path;

The request path without query string.

params

string[string] params;

Path parameters extracted by the router, keyed by parameter name.

query

string[string] query;

Query parameters parsed from the request line.

headers

string[string] headers;

Request headers keyed by lower-cased name.

content

ubyte[] content;

Raw request content.

Response

struct Response;

An outbound HTTP response built by a route handler.

status

ushort status;

HTTP status code.

reason

string reason;

HTTP reason phrase.

headers

string[string] headers;

Response headers keyed by lower-cased name.

content

ubyte[] content;

Raw response content.

ok

static Response ok(JSONValue json);

A 200 response carrying a JSON value as-is.

okValue

static Response okValue(JSONValue value);

A 200 response wrapping a value in the W3C {"value": ...} envelope.

noContent

static Response noContent();

A 204 response with no content.

withJSON

static Response withJSON(ushort status, string reason, JSONValue json);

A response with the given status carrying a JSON value.

error

static Response error(ushort status, string reason, string errorCode, string message);

A JSON error response using the W3C {"value": {"error", "message"}} envelope.

Handler

alias Handler = Response delegate(Request request);

A route handler invoked when a request matches a registered route.

Router

class Router;

A minimal method-plus-pattern router with path parameter extraction.

Patterns use <name> segments to capture path parameters into Request.params, e.g. /se/grid/distributor/node/<nodeId>/drain binds nodeId. Matching is segment-wise and case-sensitive. The first registered match wins.

add

void add(string method, string pattern, Handler handler);

Registers a handler for a method and path pattern.

Parameters:

Name Description
string method The HTTP method, uppercase.
string pattern The path pattern with optional <name> parameter segments.
Handler handler The delegate invoked on a matching request.

dispatch

Response dispatch(Request request);

Dispatches a request to the first matching route.

Path parameters are extracted into a copy of the request before the handler runs, so the caller's request is not mutated.

Parameters:

Name Description
Request request The inbound request.

Returns: The handler response, or a 404 error response when no route matches.