matt-42 / silicon

A high performance, middleware oriented C++14 http web framework please use matt-42/lithium instead
http://siliconframework.org
MIT License
1.72k stars 138 forks source link

Headers in request and response #26

Closed iceydee closed 8 years ago

iceydee commented 8 years ago

I'd like to be able to read the headers from a request and also be able to add/modify the response headers - how could that be accomplished? middleware?

matt-42 commented 8 years ago

I just added get_header for the mhd_request and set_header/set_cookie for the mhd_response class. (Update the the last revision of the master branch).

You can just request them via your procedure argument (note the use of pointers in the argument type):

GET / _hello = [] (mhd_response* resp)
{
  resp->set_header("Content-Type", "application/json")
}

The implementation is here: https://github.com/matt-42/silicon/blob/master/silicon/backends/mhd.hh#L40