Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Poco c++Net: Http get headers from response

Im using POCO C++ Net libraries for http

I want to try make a strategy for persistent caching.

First of all I think I need to get expires from the cache headers and cross check with cached values (please tell me if I'm wrong).

So how can I extract the cache header from httpResponse?

I've seen that you can do this in Java, (getFirstHeader()), but how do I do it in POCO C++?

Below is an ordinary http GET-request using POCO:

try
{
    // prepare session
    URI uri("http://www.google.se");
    HTTPClientSession session(uri.getHost(), uri.getPort());

    // prepare path
    string path(uri.getPathAndQuery());
    if (path.empty()) path = "/";

    // send request
    printnet(path.c_str());
    HTTPRequest req(HTTPRequest::HTTP_GET, path, HTTPMessage::HTTP_1_1);
    session.sendRequest(req);

    // get response
    printnet("Get response");

    HTTPResponse res;
    cout << res.getStatus() << " " << res.getReason() << endl;

    // print response
    istream &is = session.receiveResponse(res);
    StreamCopier::copyStream(is, cout);
}
catch (Exception &ex)
{
    printnet(ex.displayText().c_str());
    return -1;
}
return 0;
like image 728
David Karlsson Avatar asked Dec 20 '22 07:12

David Karlsson


1 Answers

So how can i extract the cache header from httpResponse?

res.get("Cache-control");
like image 86
Alex Avatar answered Dec 24 '22 02:12

Alex