Skip to content

Commit

Permalink
Fix HTTP listener teardown in HTTP2 example.
Browse files Browse the repository at this point in the history
  • Loading branch information
s-ludwig committed Jun 28, 2024
1 parent 14bb98b commit f36ff1c
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions examples/http2/source/app.d
Original file line number Diff line number Diff line change
Expand Up @@ -44,20 +44,21 @@ void main()
{
//import vibe.core.log;
//setLogLevel(LogLevel.trace);
HTTPListener[] listeners;

/* ==== cleartext HTTP/2 support (h2c) ==== */
auto settings = new HTTPServerSettings;
settings.port = 8090;
settings.bindAddresses = ["127.0.0.1"];
settings.options |= HTTPServerOption.enableHTTP2;
listenHTTP(settings, &handleReq);
listeners ~= listenHTTP(settings, &handleReq);

/* ==== cleartext HTTP/2 support (h2c) with a heavy DATA frame ==== */
auto bigSettings = new HTTPServerSettings;
bigSettings.port = 8092;
bigSettings.bindAddresses = ["127.0.0.1"];
bigSettings.options |= HTTPServerOption.enableHTTP2;
listenHTTP(bigSettings, &bigHandleReq!100000);
listeners ~= listenHTTP(bigSettings, &bigHandleReq!100000);

/* ========== HTTPS (h2) support ========== */
auto tlsSettings = new HTTPServerSettings;
Expand All @@ -72,7 +73,7 @@ void main()

// set alpn callback to support HTTP/2 protocol negotiation
tlsSettings.tlsContext.alpnCallback(http2Callback);
listenHTTP(tlsSettings, &tlsHandleReq);
listeners ~= listenHTTP(tlsSettings, &tlsHandleReq);

/* ========== HTTPS (h2) support with a heavy DATA frame ========== */
auto bigTLSSettings = new HTTPServerSettings;
Expand All @@ -87,8 +88,11 @@ void main()

// set alpn callback to support HTTP/2 protocol negotiation
bigTLSSettings.tlsContext.alpnCallback(http2Callback);
auto l = listenHTTP(bigTLSSettings, &bigHandleReq!100000);
scope(exit) l.stopListening();
listeners ~= listenHTTP(bigTLSSettings, &bigHandleReq!100000);

scope(exit)
foreach (l; listeners)
l.stopListening();

/* ========== Run both `listenHTTP` handlers ========== */
// UNCOMMENT to run
Expand Down

0 comments on commit f36ff1c

Please sign in to comment.