Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to free kreq without flushing HTTP data stream? #78

Open
aggsol opened this issue Feb 6, 2020 · 2 comments
Open

How to free kreq without flushing HTTP data stream? #78

aggsol opened this issue Feb 6, 2020 · 2 comments

Comments

@aggsol
Copy link

aggsol commented Feb 6, 2020

Assume while writing data for a normal (e. g. HTTP 200 HTML) response one of the write fails with KCGI_ENOMEM. How can I the free the kreq without writing any HTTP data or discarding any data written previously? Because an error occurred I would now create a new empty response (e.g. HTTP 500).

@kristapsdz
Copy link
Owner

Good question. kcgi will flush headers as soon as they finish, so even if you have a big send buffer (in struct kopt) and simply terminate on ENOMEM, in effect not sending any data, your web server is still going to get the status code. It shouldn't be too difficult to add a struct kopt option that buffers the entire response, including the headers, which would allow you to terminate without sending any data and relying on the web server to interpret that as a 500. The modification would be in output.c, kdata_body(), where you an already see that I explain why I'm draining the buffer and whether there should be an option for it.

@aggsol
Copy link
Author

aggsol commented Feb 18, 2020

I worked around it by buffering the whole response and setting up the headers and status at the very last moment and use a single write. Any error prior this will be handled as a well formed HTTP 500. If still something goes wrong then at the end I just throw an exception and let the webserver handle the terminated CGI process.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants