From: David H. <dav...@gm...> - 2011-01-09 21:32:22
|
Howdy all, I've just started working with cpp-netlib and I am trying to get an HTTP server (not asynchronous) working with different mime Content-Types. I see that the FileServer example sets the mime-type for different responses in the asynchronous server connection_ptr but I can't get anything like it to work for a simple synchronous server response. Can anyone give an example of how to set the Content-Type header for a simple synchronous server response? Thanks, -Dave- |
From: Raindog <ra...@ma...> - 2011-01-09 23:44:03
|
On 1/9/2011 1:32 PM, David Hite wrote: > Howdy all, > > I've just started working with cpp-netlib and I am trying to get an > HTTP server (not asynchronous) working with different mime Content-Types. > > I see that the FileServer example sets the mime-type for different > responses in the asynchronous server connection_ptr but I can't get > anything like it to work for a simple synchronous server response. > > Can anyone give an example of how to set the Content-Type header for a > simple synchronous server response? > > Thanks, > -Dave- http_client_t::request login_req(url); http_client_t client; login_req << net::header("Content-Length", boost::lexical_cast<std::string>(auth_string.length())); login_req << net::header("Content-Type", "application/x-www-form-urlencoded"); login_req << net::body(auth_string); http_client_t::response auth_resp = client.post(login_req); |
From: Dean M. B. <mik...@gm...> - 2011-01-10 04:41:42
|
Hi David, On Mon, Jan 10, 2011 at 5:32 AM, David Hite <dav...@gm...> wrote: > Howdy all, > I've just started working with cpp-netlib and I am trying to get an HTTP > server (not asynchronous) working with different mime Content-Types. > I see that the FileServer example sets the mime-type for different responses > in the asynchronous server connection_ptr but I can't get anything like it > to work for a simple synchronous server response. > Can anyone give an example of how to set the Content-Type header for a > simple synchronous server response? Certainly. If you look in libs/network/test/http/server_hello_world.cpp there is an example of setting the headers for the response of a synchronous HTTP server. What you'll need to remember is that the response object passed by lvalue reference to the handler has a member named `headers` where you would put all the headers you want. In your handler's operator() overload, you would have something like this: server::response::header_type content_type = {"Content-Type", "application/octet-stream"}; response.headers.push_back(content_type); This is at least true for the version in the 0.9-devel branch. If you're on 0.8, you would need code that looks like this: server::response_header content_type = {"Content-Type", "application/octet-stream"}; response.headers.push_back(content_type); > Thanks, > -Dave- I hope this helps! -- Dean Michael Berris about.me/deanberris |
From: David H. <dav...@gm...> - 2011-01-10 21:41:00
|
Hey Dean, Thanks for the quick reply. I can't find the example you are talking about... i'm using 0.8 version. I'm also getting some compile errors when I try to push the content-type header on the response.headers Here's my code: Server::response_header content_type = {"Content-Type", "application/vnd.google-earth.kml+xml"}; // set message in response response = Server::response::stock_reply(Server::response::ok, kml_string); // set MIME type for response response.headers.push_back( content_type ); And here's my error: error: no matching function for call to 'std::vector<boost::network::http::request_header<boost::network::http::tags::http_server>, std::allocator<boost::network::http::request_header<boost::network::http::tags::http_server> > >::push_back(boost::network::http::response_header<boost::network::http::tags::http_server>&)' /usr/include/c++/4.4/bits/stl_vector.h:733: note: candidates are: void std::vector<_Tp, _Alloc>::push_back(const _Tp&) [with _Tp = boost::network::http::request_header<boost::network::http::tags::http_server>, _Alloc = std::allocator<boost::network::http::request_header<boost::network::http::tags::http_server> >] These error messages are impossible to decipher... any ideas? The only candidate function it's listing is using boost::network::http::request_header. I tried that too and no dice. -Dave- On Sun, Jan 9, 2011 at 9:41 PM, Dean Michael Berris <mik...@gm...>wrote: > Hi David, > > On Mon, Jan 10, 2011 at 5:32 AM, David Hite <dav...@gm...> wrote: > > Howdy all, > > I've just started working with cpp-netlib and I am trying to get an HTTP > > server (not asynchronous) working with different mime Content-Types. > > I see that the FileServer example sets the mime-type for different > responses > > in the asynchronous server connection_ptr but I can't get anything like > it > > to work for a simple synchronous server response. > > Can anyone give an example of how to set the Content-Type header for a > > simple synchronous server response? > > Certainly. If you look in > libs/network/test/http/server_hello_world.cpp there is an example of > setting the headers for the response of a synchronous HTTP server. > What you'll need to remember is that the response object passed by > lvalue reference to the handler has a member named `headers` where you > would put all the headers you want. > > In your handler's operator() overload, you would have something like this: > > server::response::header_type content_type = {"Content-Type", > "application/octet-stream"}; > response.headers.push_back(content_type); > > This is at least true for the version in the 0.9-devel branch. If > you're on 0.8, you would need code that looks like this: > > server::response_header content_type = {"Content-Type", > "application/octet-stream"}; > response.headers.push_back(content_type); > > > > Thanks, > > -Dave- > > I hope this helps! > > -- > Dean Michael Berris > about.me/deanberris > > > ------------------------------------------------------------------------------ > Gaining the trust of online customers is vital for the success of any > company > that requires sensitive data to be transmitted over the Web. Learn how to > best implement a security strategy that keeps consumers' information secure > and instills the confidence they need to proceed with transactions. > http://p.sf.net/sfu/oracle-sfdevnl > _______________________________________________ > Cpp-netlib-devel mailing list > Cpp...@li... > https://lists.sourceforge.net/lists/listinfo/cpp-netlib-devel > |
From: Dean M. B. <mik...@gm...> - 2011-01-11 03:36:02
|
On Tue, Jan 11, 2011 at 5:40 AM, David Hite <dav...@gm...> wrote: > Hey Dean, > Thanks for the quick reply. You're welcome. :) > I can't find the example you are talking about... i'm using 0.8 version. > Ah, yes, the example is only in 0.9-devel at the moment and will be coming out in 0.9 (beta coming within the week). > I'm also getting some compile errors when I try to push the content-type > header on the response.headers > > Here's my code: > > Server::response_header content_type = {"Content-Type", > "application/vnd.google-earth.kml+xml"}; > > // set message in response > response = Server::response::stock_reply(Server::response::ok, > kml_string); > > // set MIME type for response > response.headers.push_back( content_type ); > > And here's my error: > > error: no matching function for call to > 'std::vector<boost::network::http::request_header<boost::network::http::tags::http_server>, > std::allocator<boost::network::http::request_header<boost::network::http::tags::http_server> >> >>::push_back(boost::network::http::response_header<boost::network::http::tags::http_server>&)' > /usr/include/c++/4.4/bits/stl_vector.h:733: note: candidates are: void > std::vector<_Tp, _Alloc>::push_back(const _Tp&) [with _Tp = > boost::network::http::request_header<boost::network::http::tags::http_server>, > _Alloc = > std::allocator<boost::network::http::request_header<boost::network::http::tags::http_server> >>] > > These error messages are impossible to decipher... any ideas? Ah, it actually just says that you can't push a `response_header<...>` into a vector of `request_header<...>`. I remember this being something I fixed in the 0.9-devel branch and which is an oversight on my part in 0.8. > The only candidate function it's listing is using > boost::network::http::request_header. I tried that too and no dice. > Code like this should work: boost::network::http::request_header<boost::network::tags::http_server> content_type = {"Content-Type", "application/vnd.google-earth.kml+xml"}; response.push_back(content_type); If that still doesn't work, let me know because that would be a serious problem. Have a good one and I hope this helps. (Also, please try not to top-post :D) -- Dean Michael Berris about.me/deanberris |
From: David H. <dav...@gm...> - 2011-01-11 05:05:08
|
On Mon, Jan 10, 2011 at 8:35 PM, Dean Michael Berris <mik...@gm... > wrote: > On Tue, Jan 11, 2011 at 5:40 AM, David Hite <dav...@gm...> wrote: > > Hey Dean, > > Thanks for the quick reply. > > You're welcome. :) > > > I can't find the example you are talking about... i'm using 0.8 version. > > > > Ah, yes, the example is only in 0.9-devel at the moment and will be > coming out in 0.9 (beta coming within the week). > > > I'm also getting some compile errors when I try to push the content-type > > header on the response.headers > > > > Here's my code: > > > > Server::response_header content_type = {"Content-Type", > > "application/vnd.google-earth.kml+xml"}; > > > > // set message in response > > response = Server::response::stock_reply(Server::response::ok, > > kml_string); > > > > // set MIME type for response > > response.headers.push_back( content_type ); > > > > And here's my error: > > > > error: no matching function for call to > > > 'std::vector<boost::network::http::request_header<boost::network::http::tags::http_server>, > > > std::allocator<boost::network::http::request_header<boost::network::http::tags::http_server> > >> > > >>::push_back(boost::network::http::response_header<boost::network::http::tags::http_server>&)' > > /usr/include/c++/4.4/bits/stl_vector.h:733: note: candidates are: void > > std::vector<_Tp, _Alloc>::push_back(const _Tp&) [with _Tp = > > > boost::network::http::request_header<boost::network::http::tags::http_server>, > > _Alloc = > > > std::allocator<boost::network::http::request_header<boost::network::http::tags::http_server> > >>] > > > > These error messages are impossible to decipher... any ideas? > > Ah, it actually just says that you can't push a `response_header<...>` > into a vector of `request_header<...>`. I remember this being > something I fixed in the 0.9-devel branch and which is an oversight on > my part in 0.8. > > > The only candidate function it's listing is using > > boost::network::http::request_header. I tried that too and no dice. > > > > Code like this should work: > > boost::network::http::request_header<boost::network::tags::http_server> > content_type = {"Content-Type", > "application/vnd.google-earth.kml+xml"}; > response.push_back(content_type); > > If that still doesn't work, let me know because that would be a serious > problem. > > Have a good one and I hope this helps. > > (Also, please try not to top-post :D) > > -- > Dean Michael Berris > about.me/deanberris > > > ------------------------------------------------------------------------------ > Gaining the trust of online customers is vital for the success of any > company > that requires sensitive data to be transmitted over the Web. Learn how to > best implement a security strategy that keeps consumers' information secure > and instills the confidence they need to proceed with transactions. > http://p.sf.net/sfu/oracle-sfdevnl > _______________________________________________ > Cpp-netlib-devel mailing list > Cpp...@li... > https://lists.sourceforge.net/lists/listinfo/cpp-netlib-devel > Dean, I got it to work! Here's the code that works: // These are my defs for namespace & server type namespace http = boost::network::http; typedef http::server<CgiServer> Server; http::request_header<http::tags::http_server> content_type = {"Content-Type", "application/vnd.google-earth.kml+xml"}; // set message in response response = Server::response::stock_reply(Server::response::ok, kml_string); response.headers.push_back( content_type ); Thanks for your help! -Dave- |
From: Dean M. B. <mik...@gm...> - 2011-01-11 05:09:38
|
On Tue, Jan 11, 2011 at 1:05 PM, David Hite <dav...@gm...> wrote: > > Dean, > I got it to work! Cool! > Here's the code that works: > // These are my defs for namespace & server type > namespace http = boost::network::http; > typedef http::server<CgiServer> Server; > > http::request_header<http::tags::http_server> content_type = > {"Content-Type", "application/vnd.google-earth.kml+xml"}; > // set message in response > response = Server::response::stock_reply(Server::response::ok, kml_string); > response.headers.push_back( content_type ); Ah, yes, the tags are in the http namespace. I really should fix that with an example. :) > Thanks for your help! You're welcome! :) -- Dean Michael Berris about.me/deanberris |