drogonframework / drogon

Drogon: A C++14/17/20 based HTTP web application framework running on Linux/macOS/Unix/Windows
MIT License
11.57k stars 1.12k forks source link

Duplicate http header "content-length" #1846

Closed IYinxf closed 6 months ago

IYinxf commented 11 months ago

Describe the bug Duplicate http header "content-length". I need to send the file length to the front end using "content-length", but the content is empty. This will make pdf.js read the range required for PDF file parsing.

To Reproduce Steps to reproduce the behavior:

  1. auto resp = HttpResponse::newHttpResponse();resp->addHeader("content-length", not_zero); without any http body;
  2. when the program reaches lines 537 to 544 of HttpResponseImpl.cc, "content-length:0" is added to the http header.

In the second step, should we determine whether there is no "content-length" in the member headers_?

}}_1X0Z I $2I@Y`6@J5`1H

_T@O 1_}{D21KF)B9LP5}2C

RMO5A 2LWV6O8PHR1IJ FE1

Expected behavior only once "content-length" in http headers.

Screenshots If applicable, add screenshots to help explain your problem.

Desktop :

an-tao commented 11 months ago

@IYinxf Thanks for your feed back. I think users should not set the Content-Length header themselves. The framework will set this header based on the actual size of the body (even after the framework automatically compresses the body). No checks are performed for performance reasons.