microsoft / cpprestsdk

The C++ REST SDK is a Microsoft project for cloud-based client-server communication in native code using a modern asynchronous C++ API design. This project aims to help C++ developers connect to and interact with services.
Other
8.01k stars 1.66k forks source link

Content-length header missing in response on Win10 UWP with compressed response #315

Open jhandley opened 7 years ago

jhandley commented 7 years ago

When sending a GET request to a server that responds with gzip encoding in a UWP on Windows 10 the content-length and content-encoding headers are not included in the http_response::headers(). Both of the headers are visible in Wireshark so they must be getting removed somewhere along the line.

Without the content-length of the response there is no way to show download progress.

Test code:

    http_client client(U("http://www.teleyah.com"));

    auto requestTask = client.request(methods::GET).then([=](http_response response)
    {
        for (auto h : response.headers()) {
            OutputDebugString(h.first.c_str());
            OutputDebugString(L" : ");
            OutputDebugString(h.second.c_str());
            OutputDebugString(L"\n");
        }
    });

    try {
        requestTask.wait();
    }
    catch (const std::exception &e) {
    }
ras0219-msft commented 7 years ago

We have explicit APIs for manipulating some headers (such as content length), which is why they are not present in the normal map. See http_headers::content_length().

jhandley commented 7 years ago

http_headers::content_length() returns zero in my test app. From I what see in the source code it just does a lookup in the header map.

ras0219-msft commented 7 years ago

You're right. I'll take a look into this.