Luukdegram / apple_pie

Basic HTTP server implementation in Zig
MIT License
163 stars 21 forks source link

unable to force connection: close on the server #59

Closed vrischmann closed 3 years ago

vrischmann commented 3 years ago

Hi,

When running in io_mode = .blocking, the connection is always closed here, however the response always writes Connection: keep-alive here.

Some clients are fine with this but for example the scraper from VictoriaMetrics isn't.

I fixed this by adding a close field in Response and writing the Connection: close header accordingly. I'm not sure if that's the best way to do it but if it's acceptable I can make a PR.

Any advice ?

Luukdegram commented 3 years ago

A flag to tell the response to close sounds like the right solution. However, I think we should populate such flag before providing the Response object to the user, based on the event_mode and the Request (in case client sent close). This will also allow the user to observe the flag and make decisions on that without having to re-implement the logic themselves. While allowed to overwrite the flag, it's the user's responsibility to understand the implications of doing so. (We should definitely provide a comment explaining what the flag/field does)