Re: [Cppcms-users] async connections and response headers
Brought to you by:
artyom-beilis
From: Artyom <art...@ya...> - 2010-07-14 08:41:20
|
Ok, after quick look on our code the problem is obvious: You can't change response headers **after** writing data to output stream as in *CGI protocol all headers must be written before the response body. See: http://art-blog.no-ip.info/cppcms_ref_v0_99_1/classcppcms_1_1http_1_1response.html#39e48c676a3f2c79b26d60b8d455658c So you must do all changed in headers before writing to output stream. So instead of: release_context()->async_complete_response(); You need: response().set_content_header("text/plain"); response().status(200); response().out() << "test"; release_context()->async_complete_response(); Notes: - Status is assumed be default in CGI protocols as 200, so you don't need to set it explicitly, one status like 404, 400 or 301 require explicit CGI header Status: - You may use response().set_plain_text_header() instead of writing: response().set_content_header("text/plain"); (which does the same). So in short you may write this as: response().set_plain_text_header(); response().out() << "test"; release_context()->async_complete_response(); Note, set_content_header(std::string) still adds charset by default, See: http://art-blog.no-ip.info/cppcms_ref_v0_99_1/classcppcms_1_1http_1_1response.html#50ae55ff605bc655f5b19021f0f4f71d So if you want to set raw header use set_header(name,value) function. > what remains is the header issue. my test application still sends only > the content without headers. i attached capture from wireshark of the > http conversation between server and browser and the scgi conversation > between nginx and the application. while in the http conversation no > response headers are shown the scgi dump shows that at least > content-type and x-powered had been sent. nginx obviously filtered them > out due to the missing standard headers. the test application has been > compiled against svn-1317. > > i also attached the application again since i did the changes you > suggested. i also tried to set the status code explicitly without success. > Artyom |