Browse Source

* Merging revisions 44775 from trunk:
------------------------------------------------------------------------
r44775 | michael | 2020-04-18 12:36:03 +0200 (Sat, 18 Apr 2020) | 1 line

* Fix bug #36851: Content-Length header needs to be removed if automatically added
------------------------------------------------------------------------

git-svn-id: branches/fixes_3_2@45048 -

michael 5 years ago
parent
commit
97f098786c
1 changed files with 6 additions and 2 deletions
  1. 6 2
      packages/fcl-web/src/base/fphttpclient.pp

+ 6 - 2
packages/fcl-web/src/base/fphttpclient.pp

@@ -656,7 +656,8 @@ procedure TFPCustomHTTPClient.SendRequest(const AMethod: String; URI: TURI);
 Var
   PH,UN,PW,S,L : String;
   I : Integer;
-
+  AddContentLength : Boolean;
+  
 begin
   S:=Uppercase(AMethod)+' '+GetServerURL(URI)+' '+'HTTP/'+FHTTPVersion+CRLF;
   UN:=URI.Username;
@@ -683,7 +684,8 @@ begin
   If (URI.Port<>0) then
     S:=S+':'+IntToStr(URI.Port);
   S:=S+CRLF;
-  If Assigned(RequestBody) and (IndexOfHeader('Content-Length')=-1) then
+  AddContentLength:=Assigned(RequestBody) and (IndexOfHeader('Content-Length')=-1);
+  If AddContentLength then
     AddHeader('Content-Length',IntToStr(RequestBody.Size));
   CheckConnectionCloseHeader;
   For I:=0 to FRequestHeaders.Count-1 do
@@ -692,6 +694,8 @@ begin
     If AllowHeader(L) then
       S:=S+L+CRLF;
     end;
+  If AddContentLength then
+    FRequestHeaders.Delete(FRequestHeaders.IndexOfName('Content-Length'));
   if Assigned(FCookies) then
     begin
     L:='Cookie: ';