vibe.d beta banner
get vibe.d
0.10.1

Asynchronous I/O that doesn’t get in your way, written in D

Function sendFile

Sends a file to the given HTTP server response object.

void sendFile (
  scope HTTPServerRequest req,
  scope HTTPServerResponse res,
  GenericPath!(vibe.core.path.PosixPathFormat) path,
  HTTPFileServerSettings settings = null
) @safe;

When serving a file, certain request headers are supported to avoid sending the file if the client has it already cached. These headers are "If-Modified-Since" and "If-None-Match". The client will be delivered with the necessary "Etag" (generated from size and last modification time of the file) and "Last-Modified" headers.

The cache control directives "Expires" and/or "Cache-Control" will also be emitted if the HTTPFileServerSettings.maxAge field is set to a positive duration and/or HTTPFileServerSettings.cacheControl has been set.

Finally, HEAD requests will automatically be handled without reading the actual file contents. Am empty response body is written instead.

Parameters

NameDescription
req The incoming HTTP request - cache and modification headers of the request can influence the generated response.
res The response object to write to.
path Path to the file to be sent.
settings Optional settings object enabling customization of how the file gets served.
Authors

Sönke Ludwig

Copyright

© 2012-2015 RejectedSoftware e.K.

License

Subject to the terms of the MIT license, as written in the included LICENSE.txt file.