Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- module vibe.http.internal.http1;
- import vibe.core.stream;
- /* TODO:
- * decide how to manage InterfaceProxy
- * allocators policy needs to be discussed
- *
- * NOTE:
- * we cannot use scope (exit) connection.close() anymore,
- * connection teardown is performed inside the callback
- */
- private void handleHTTP1Connection(ConnectionStream)(ConnectionStream connection)
- if (isConnectionStream!ConnectionStream)
- @safe {
- InterfaceProxy!Stream http_stream = connection;
- HTTPServerSettings settings;
- bool keep_alive;
- // get context
- auto context = getDefaultHTTPContext(local_address);
- connection.tcpNoDelay = true;
- () @trusted {
- import vibe.internal.utilallocator: RegionListAllocator;
- version (VibeManualMemoryManagement)
- scope request_allocator = new RegionListAllocator!(shared(Mallocator), false)(1024, Mallocator.instance);
- else
- scope request_allocator = new RegionListAllocator!(shared(GCAllocator), true)(1024, GCAllocator.instance);
- // first request
- connection.waitForDataAsync(
- (status) {
- if (status) {
- handleRequest (http_stream, connection, context, settings,
- keep_alive, request_allocator);
- } else {
- logDebug("Client didn't send the initial request in a timely manner. Closing connection.");
- connection.close();
- }
- }, 10.seconds);
- // process further requests
- connection.waitForDataAsync(
- (status) {
- if (status) {
- handleRequest (http_stream, connection, context, settings,
- keep_alive, request_allocator);
- } else if (!keep_alive) {
- // teardown
- logTrace("No keep-alive - disconnecting client.")
- connection.close()
- }
- }, settings.keepAliveTimeout);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement