Resource

Static resource

Members

Functions

handler
void handler(HTTPServerRequest req, HTTPServerResponse res)

Static variables

data
string data;
Undocumented in source.
etag
string etag;
Undocumented in source.
mime
string mime;
Undocumented in source.

Examples

It should store the the valid properties

Resource!"tmp/test.css" resource;
resource.data.should.equal("data");
resource.mime.should.equal("text/css");
resource.etag.should.equal("8D777F385D3DFEC8815D20F7496026DC");

Resource!"tmp/test.js" resourceJs;
resourceJs.mime.should.equal("text/javascript");

It should get a resource with the right headers

Resource!"tmp/test.css" resource;

auto router = new URLRouter();
router.get("/resource", &resource.handler);

router
  .request
  .get("/resource")
  .expectHeader("ETag", resource.etag)
  .expectHeader("Content-Type", "text/css")
  .expectStatusCode(200)
  .end((Response response) => {
    response.bodyString.should.equal("data");
  });

It should not get a resource with the etag matches

Resource!"tmp/test.css" resource;

auto router = new URLRouter();
router.get("/resource", &resource.handler);

router
  .request
  .get("/resource")
  .header("If-None-Match", resource.etag)
  .expectHeader("ETag", resource.etag)
  .expectStatusCode(304)
  .end((Response response) => {
    response.bodyString.should.equal("");
  });

Meta