File tree 2 files changed +15
-1
lines changed
2 files changed +15
-1
lines changed Original file line number Diff line number Diff line change @@ -401,6 +401,19 @@ void HttpMessage::FillContentType() {
401
401
return ;
402
402
}
403
403
404
+ bool HttpMessage::NeedContentLength () {
405
+ if (type == HTTP_RESPONSE) {
406
+ HttpResponse* res = (HttpResponse*)(this );
407
+ if (res->status_code / 100 == 1 ||
408
+ res->status_code == HTTP_STATUS_NO_CONTENT ||
409
+ res->status_code == HTTP_STATUS_NOT_MODIFIED) {
410
+ return false ;
411
+ }
412
+ return true ;
413
+ }
414
+ return false ;
415
+ }
416
+
404
417
void HttpMessage::FillContentLength () {
405
418
auto iter = headers.find (" Content-Length" );
406
419
if (iter != headers.end ()) {
@@ -411,7 +424,7 @@ void HttpMessage::FillContentLength() {
411
424
content_length = body.size ();
412
425
}
413
426
if (iter == headers.end () && !IsChunked () && content_type != TEXT_EVENT_STREAM) {
414
- if (content_length != 0 || type == HTTP_RESPONSE ) {
427
+ if (content_length != 0 || NeedContentLength () ) {
415
428
headers[" Content-Length" ] = hv::to_string (content_length);
416
429
}
417
430
}
Original file line number Diff line number Diff line change @@ -253,6 +253,7 @@ class HV_EXPORT HttpMessage {
253
253
void FillContentType ();
254
254
// body.size -> content_length <-> headers["Content-Length"]
255
255
void FillContentLength ();
256
+ bool NeedContentLength ();
256
257
257
258
bool IsChunked ();
258
259
bool IsKeepAlive ();
You can’t perform that action at this time.
0 commit comments