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

Possibility to add a custom HTTP header ? #59

Closed zxvfxwing closed 7 years ago

zxvfxwing commented 7 years ago

Hi,

I wanted to know if it's possible to add a custom HTTP header for response-header -- I mean, to the server (I'm using Ajax to get data from C++ API).

My only solution here, is to make Silicon running behind a reverse proxy (nginx, where I can put the custom header).

Thank you.

matt-42 commented 7 years ago

Yes this is possible with the mhd backend:

[] (mhd_response* r)
  {
    req->set_header("header_key", "value");
  });
zxvfxwing commented 7 years ago

Can I have an example more specific please ?

i.e:

GET / _login * get_parameters(_id = int())  = [] (auto param) {
    return param.id;
}

Where do I place the mhd_response ?

Thank you.

matt-42 commented 7 years ago

Just add it to the parameter: [] (auto param, mhd_response* r) {

zxvfxwing commented 7 years ago

Thank you, it's actually working great 👍