Re: [Cppcms-users] async connections and response headers
Brought to you by:
artyom-beilis
From: Frank E. <fra...@an...> - 2010-07-14 09:24:58
|
thanks for pointing this out. it now works (yippie) but if i omit setting the status explicit to 200 i still get no response headers. from your mail i think it should default to 200 - shouldn't it? or is this a flaw in the nginx's scgi implementation.. thanks again, frank. Am 14.07.2010 10:41, schrieb Artyom: > 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 > > > > > ------------------------------------------------------------------------------ > This SF.net email is sponsored by Sprint > What will you do first with EVO, the first 4G phone? > Visit sprint.com/first -- http://p.sf.net/sfu/sprint-com-first > _______________________________________________ > Cppcms-users mailing list > Cpp...@li... > https://lists.sourceforge.net/lists/listinfo/cppcms-users -- Dipl.-Ing. (FH) Frank Enderle anamica UG (haftungsbeschränkt) Beinsteinerstr. 6 71334 Waiblingen Telefon: +49 151 14981091 Telefax: +49 7151 1335770 E-Mail: fra...@an... Internet: www.anamica.de Handelsregister: AG Stuttgart HRB 732357 Geschäftsführer: Yvonne Holzwarth, Frank Enderle |