Commit b0e247e1 authored by jan.koester's avatar jan.koester
Browse files

fxied

parent cefe7eb9
Loading
Loading
Loading
Loading
+19 −1
Changes for src/http.cpp: 19 added lines, 1 removed line.
Original line number Diff line number Diff line
@@ -210,7 +210,8 @@ libhttppp::HttpClient::HttpClient(const HttpUrl &desturl) : _url(desturl), _srvs
  _srvsock = std::make_unique<netplus::tcp>(_url.getHost().c_str(), _url.getPort(),1,0);
  _cltsock = std::make_unique<netplus::tcp>();
  _cltsock->connect(_srvsock);
  _cltsock->setTimeout(1);
  _cltsock->setNonBlock();
  _srvsock->setNonBlock();
}

void libhttppp::HttpClient::reconnect(){
@@ -427,6 +428,7 @@ const std::vector<char> libhttppp::HttpClient::Post(libhttppp::HttpRequest &nreq
      rlen=res.getContentLength();
    }

    // ... (Your loop start)
    if(!chunked){
      do{
        try{
@@ -437,6 +439,15 @@ const std::vector<char> libhttppp::HttpClient::Post(libhttppp::HttpRequest &nreq
              cpos=0;
              try{
                recv=_cltsock->recvData(data);

                // 🚨 CRITICAL FIX: Check if recv is 0 (EOF) or less
                if (recv <= 0) {
                  // If we expected more data (rlen > 0) but got EOF,
                  // it's a premature connection close.
                  throw netplus::NetException()
                  [netplus::NetException::Error] << "Premature EOF while reading HTTP response body.";
                }

                break;
              }catch(netplus::NetException &e){
                if(e.getErrorType()==netplus::NetException::Note){
@@ -478,6 +489,13 @@ const std::vector<char> libhttppp::HttpClient::Post(libhttppp::HttpRequest &nreq
          for(;;){
            try{
              recv=_cltsock->recvData(data);
              if (recv <= 0) {
                    if (readed > 0) {
                        throw netplus::NetException()
                            [netplus::NetException::Error] << "Premature EOF while reading chunked body.";
                    }
                    break;
              }
              break;
            }catch(netplus::NetException &e){
                if(e.getErrorType()!=netplus::NetException::Note){