Overview
Features
Download
Documentation
Community
Add-Ons & Services

Content-Encoding in a POCO::Net::HTTPResponse

Please post support and help requests here.

Content-Encoding in a POCO::Net::HTTPResponse

Postby karel » 08 Jul 2014, 19:49

Hello knowledgable folks,

This message was also posted on http://stackoverflow.com/questions/24635983/how-do-i-get-the-content-encoding-in-a-poconethttpresponse-object, I'm crossposting here hoping for a quick reply..

I'm fetching a server page using Poco::Net::HTTPClientSession with an appropriate Poco::Net::HTTPRequest, which works fine. Now I get a response back, and sometimes the returned page will be gzipped. I need to find out when that is the case, so that I may deflate if necessary. The HTTP header that should indicate this, is Content-Encoding: gzip; but there's no getContentEncoding() method in Poco::Net::HTTPResponse.

Here's a non-working snippet (because there's no resp.getContentEncoding()):
Code: Select all
// resp is the Poco::Net::HTTPResponse object,
// sess is the Poco::Net::HTTPClientSession
std::istream &in = sess.receiveResponse(resp);

// Get the server-returned body as a string (potentially deflate)
std::ostringstream serveroutput;
if (resp.getContentEncoding() == "gzip") {
    Poco::InflatingInputStream
        inflater(in, Poco::InflatingStreamBuf::STREAM_GZIP);
    Poco::StreamCopier::copyStream(inflater, serveroutput);
} else
    Poco::StreamCopier::copyStream(in, serveroutput);

// Now we can get at the body as a string
std::string txt = serveroutput.str();


Does anyone know how to get at the raw headers, so that I can inspect the header Content-Encoding myself, or of another useful method to determine whether a server response is gzipped? All help appreciated, TIA!
karel
 
Posts: 1
Joined: 08 Jul 2014, 19:26

Return to Support

Who is online

Users browsing this forum: No registered users and 1 guest

cron