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

Why does POST http_request time out after 100 seconds when trying to read a stream? #1603

Closed ptitzlabs closed 3 years ago

ptitzlabs commented 3 years ago

I'm trying to connect to a lightstreamer service using cpprestsdk http_client. So something along the lines of ...

  http_client clt("https://demo-apd.marketdatasystems.com");
  clt.request(methods::POST, "/lightstreamer/create_session.txt",
              "LS_user=<user>&LS_password=<password>","application/x-www-form-urlencoded")
      .then([](http_response rsp) {
        auto body = rsp.body();
        while (!body.is_eof())
        {
          Concurrency::streams::container_buffer<std::string> buffer;
          body.read_line(buffer).get();
          std::cout << buffer.collection() << std::endl;
        }
      });

I'm able to connect to stream, get the data, etc... But after exactly 100 seconds from starting it gets stuck at the body.read_line(buffer), and that's that. I've tried an identical POST request using curl

curl -v -N -X POST -d "LS_user=<user>&LS_password=<password>" https://demo-apd.marketdatasystems.com/lightstreamer/create_session.txt
Note: Unnecessary use of -X or --request, POST is already inferred.
*   Trying 195.234.39.34:443...
* Connected to demo-apd.marketdatasystems.com (195.234.39.34) port 443 (#0)
* ALPN, offering h2
* ALPN, offering http/1.1
* successfully set certificate verify locations:
*  CAfile: /etc/ssl/certs/ca-certificates.crt
*  CApath: /etc/ssl/certs
* TLSv1.3 (OUT), TLS handshake, Client hello (1):
* TLSv1.3 (IN), TLS handshake, Server hello (2):
* TLSv1.2 (IN), TLS handshake, Certificate (11):
* TLSv1.2 (IN), TLS handshake, Server key exchange (12):
* TLSv1.2 (IN), TLS handshake, Server finished (14):
* TLSv1.2 (OUT), TLS handshake, Client key exchange (16):
* TLSv1.2 (OUT), TLS change cipher, Change cipher spec (1):
* TLSv1.2 (OUT), TLS handshake, Finished (20):
* TLSv1.2 (IN), TLS handshake, Finished (20):
* SSL connection using TLSv1.2 / ECDHE-RSA-AES256-GCM-SHA384
* ALPN, server did not agree to a protocol
* Server certificate:
*  subject: C=GB; postalCode=EC4R 2YA; L=London; street=25 Dowgate Hill; street=Cannon Bridge House; O=Market Data Limited; OU=IT; CN=*.marketdatasystems.com
*  start date: Jul 24 00:00:00 2020 GMT
*  expire date: Jul 24 23:59:59 2021 GMT
*  subjectAltName: host "demo-apd.marketdatasystems.com" matched cert's "*.marketdatasystems.com"
*  issuer: C=GB; ST=Greater Manchester; L=Salford; O=Sectigo Limited; CN=Sectigo RSA Organization Validation Secure Server CA
*  SSL certificate verify ok.
> POST /lightstreamer/create_session.txt HTTP/1.1
> Host: demo-apd.marketdatasystems.com
> User-Agent: curl/7.74.0
> Accept: */*
> Content-Length: 177
> Content-Type: application/x-www-form-urlencoded
> 
* upload completely sent off: 177 out of 177 bytes
* Mark bundle as not supporting multiuse
< HTTP/1.1 200 OK
< Server: Lightstreamer-Server/7.0.3 build 1885.8 (Lightstreamer Server - www.lightstreamer.com) ENTERPRISE edition
< Content-Type: text/enriched; charset=ISO-8859-1
< Cache-Control: no-store
< Cache-Control: no-transform
< Cache-Control: no-cache
< Pragma: no-cache
< Expires: Thu, 1 Jan 1970 00:00:00 GMT
< Date: Sat, 27 Mar 2021 21:32:05 GMT
< Transfer-Encoding: chunked
< 
OK

And it works fine - doesn't time out or gets stuck, just keeps reading the stream line by line. So why does cpprestsdk http_request stall after 100s, and what can I do to prevent it from stalling?