davidmoreno / onion

C library to create simple HTTP servers and Web Applications.
http://www.coralbits.com/libonion/
Other
2.02k stars 252 forks source link

Allow external header management. #168

Closed bitfehler closed 8 years ago

bitfehler commented 8 years ago

This introduces an option to have the framework hand over header management to the application. The header section will not be finished automatically and the app can keep adding headers via the usual write functions. It also becomes the app's responsibility to end the header section before sendind the body.

This option is useful to proxy requests to CGI apps, but can probably come in handy in other situations as well.

bitfehler commented 8 years ago

Hi, first of all, thanks for this interesting framework! I just started playing with it, but it looks really promising.

Maybe to elaborate a little on the PR: one might think CGI apps are somewhat out of fashion, but one prominent example is git http-backend. Using a version of onion patched with this PR I can basically do something like:

// Poor man's CGI:
onion_response_set_app_headers(res, true);
onion_dict *headers = onion_response_get_headers(res);
onion_dict_remove(headers, "Content-Type");

and then pipe the output of git http-backend into the response, which looks somewhat like this:

Expires: Fri, 01 Jan 1980 00:00:00 GMT
Pragma: no-cache
Cache-Control: no-cache, max-age=0, must-revalidate
Content-Length: 11720
Content-Type: text/plain

8b8d3f1f6d892b4e022a6c5c1fd192016b29859b    refs/heads/dns
5ec0353a7c06c51053995bba76e3fd0143e7a8d8    refs/heads/master

I am aware that this probably constitutes an edge use case and thus tried to make the patch as uninvasive as possible. I hope you find it acceptable :)

Cheers, Conrad

davidmoreno commented 8 years ago

Hi,

looks good, but I would love to see an example of use, maybe just a minimal interaction with git http-backend.

A test would be nice too.

Regards, David.

bitfehler commented 8 years ago

Hi, sorry, it was only after the patch submission that I started to hit another road-block, I think this approach probably doesn't make sense in the end. Rather, a proper CGI interface would have to be implemented, but that will take some time. In the meantime, feel free to close this PR. Sorry for the noise.

davidmoreno commented 8 years ago

No prob. Keep us informed if you plan to keep working on this.