Response

Constructors

this
this(ubyte[] data, ulong len)

Instantiate the Response

Members

Functions

bodyJson
Json bodyJson()

get the body as a json object

bodyString
string bodyString()

get the body as a string

toString
string toString()

get the request as a string

Variables

bodyRaw
ubyte[] bodyRaw;
Undocumented in source.
headers
string[string] headers;
statusCode
int statusCode;

Examples

Expect header

1 auto router = new URLRouter();
2 
3 void respondHeader(HTTPServerRequest, HTTPServerResponse res)
4 {
5   res.headers["some-header"] = "some-value";
6   res.writeBody("");
7 }
8 
9 router.get("*", &respondHeader);
10 
11 
12 // Check for the exact header value:
13 request(router)
14   .get("/")
15   .expectHeader("some-header", "some-value")
16     .end();
17 
18 
19 ({
20   request(router)
21     .post("/")
22     .expectHeader("some-header", "some-value")
23       .end();
24 }).should.throwAnyException.msg.should.contain("Response header `some-header` is missing.");
25 
26 ({
27   request(router)
28     .get("/")
29     .expectHeader("some-header", "other-value")
30       .end();
31 }).should.throwAnyException.msg.should.contain("Response header `some-header` has an unexpected value");
32 
33 // Check if a header exists
34 request(router)
35   .get("/")
36   .expectHeaderExist("some-header")
37     .end();
38 
39 
40 ({
41   request(router)
42     .post("/")
43     .expectHeaderExist("some-header")
44       .end();
45 }).should.throwAnyException.msg.should.contain("Response header `some-header` is missing.");
46 
47 // Check if a header contains a string
48 request(router)
49   .get("/")
50   .expectHeaderContains("some-header", "value")
51     .end();
52 
53 ({
54   request(router)
55     .get("/")
56     .expectHeaderContains("some-header", "other")
57       .end();
58 }).should.throwAnyException.msg.should.contain("Response header `some-header` has an unexpected value.");

Meta