TFPHTTPClient holds the last cookie only lazarus / 38-Networking and Web Programming ---------------------------------------------------------------------- engkin · 2018-03-17 12:37 I believe this is a bug in TFPCustomHTTPClient. I tracked it down to ReadResponseHeaders: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i function TFPCustomHTTPClient.ReadResponseHeaders: integer;   Procedure DoCookies(S : String);   Var    P : Integer;    C : String;   begin  If Assigned(FCookies) then    ///  <--------  Bug      FCookies.Clear;             ///  <-------- /    P:=Pos(':',S);    System.Delete(S,1,P);    Repeat      P:=Pos(';',S);      If (P=0) then        P:=Length(S)+1;      C:=Trim(Copy(S,1,P-1));      Cookies.Add(C);      System.Delete(S,1,P);    Until (S='') or Terminated;  end; Const  SetCookie = 'set-cookie'; Var  StatusLine,S : String; begin  if not ReadString(StatusLine) then    Exit(0);  Result:=ParseStatusLine(StatusLine);  Repeat    if ReadString(S) and (S<>'') then      begin      ResponseHeaders.Add(S);      If (LowerCase(Copy(S,1,Length(SetCookie)))=SetCookie) then        DoCookies(S);      end  Until (S='') or Terminated;  If Assigned(FOnHeaders) and not Terminated then    FOnHeaders(Self);end;It clears FCookies repeatedly instead of accumulating all received cookies. ---------------------------------------------------------------------- torumyax · 2018-03-17 12:54 I haven't tested TFPHTTPClient yet, but is there an official github repository for the TFP** libraries? That would be nice...'cause I'm struggling with TFPHttpServer right now... ---------------------------------------------------------------------- engkin · 2018-03-17 12:59 There is no official github repo. There is an official svn or web ---------------------------------------------------------------------- torumyax · 2018-03-17 13:12 Thank you for the sharing! ---------------------------------------------------------------------- Thaddy · 2018-03-17 14:59 As long as session cookies are meant, the behavior looks correct to me. If not it is indeed a bug. (But I am a cookie hater: best (intention) and worst (mis-use) idea ever invented. Servers should maintain state, not clients) ---------------------------------------------------------------------- engkin · 2018-03-17 15:29 Quote from: Thaddy on March 17, 2018, 03:59:59 pmAs long as session cookies are meant, the behavior looks correct to me. If not it is indeed a bug. (But I am a cookie hater: best (intention) and worst (mis-use) idea ever invented. Servers should maintain state, not clients) Session cookies will get deleted if did not come as the last one in a series of set-cookie headers. For instance consider: Code: Text  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i set-cookie: an=123; Expires=Sat, 17 Mar 2018 15:07:39 UTC; Path=/; Domain=.example.com; Secure;set-cookie: _active_sess=AbCdEf0123; Path=/; Domain=.example.com; Secure;set-cookie: your_guest_id=AB12CD456; Expires=Mon, 16 Mar 2020 15:07:48 UTC; Path=/; Domain=.example.comset-cookie: z=15; Expires=Mon, 16 Apr 2018 15:07:48 UTC; Path= /; Domain=.example.com; Secure ---------------------------------------------------------------------- Thaddy · 2018-03-17 15:44 So it is a bug indeed. ---------------------------------------------------------------------- engkin · 2018-03-18 03:30 Quote from: Thaddy on March 17, 2018, 04:44:07 pmSo it is a bug indeed. Thank you. I'll file a bug report when I get a chance. Edit: Filed. ---------------------------------------------------------------------- Soner · 2021-01-24 19:19 It looks like your bugfix did not solve the bug. TFPHTTPClient still holds only last cookie in fpc 3.2.1-Svn 62267 and latest svn version.(My fpc  contains your bugfix). I uploaded  test project with server and httpclient app. Chrome- Browser holds cookie until it is closed, but TFPHTTPClient loses it after second call. Maybe you should open the bug report again. ---------------------------------------------------------------------- trev · 2021-01-25 03:52 Quote from: Soner on January 24, 2021, 08:19:23 pmIt looks like your bugfix did not solve the bug. [...] Maybe you should open the bug report again. engkin has not logged in since April last year. I think you'd do better opening a new bug report and referencing the earlier one. ---------------------------------------------------------------------- Thaddy · 2021-01-25 08:07 Quote from: Soner on January 24, 2021, 08:19:23 pm.(My fpc  contains your bugfix). It was already applied, do not apply it yourself. 3.2.1 and 3.3.1 both have the patch applied. re-patching it may break your build since many more related things in TfpHttpClient are also fixed. see https://bugs.freepascal.org/view.php?id=33451 which is back ported to 3.2.1 I believe. With proper settings only the session cookie is dropped (as it should) I am using daily builds for 3.2.1 and 3.3.1 and so should you. I tested with trunk from yesterday, but not very intensive. ---------------------------------------------------------------------- Soner · 2021-01-25 20:54 Quote from: trev on January 25, 2021, 04:52:54 amengkin has not logged in since April last year. I think you'd do better opening a new bug report and referencing the earlier one. I will, but I wanted be sure there is still bug. I thought , maybe I am making something wrong. I uploaded a test project, but still only one person downloaded it. Quote from: Thaddy on January 25, 2021, 09:07:29 amQuote from: Soner on January 24, 2021, 08:19:23 pm.(My fpc  contains your bugfix). It was already applied, do not apply it yourself. 3.2.1 and 3.3.1 both have the patch applied. re-patching it may break your build since many more related things in TfpHttpClient are also fixed. see https://bugs.freepascal.org/view.php?id=33451 which is back ported to 3.2.1 I believe. With proper settings only the session cookie is dropped (as it should) I am using daily builds for 3.2.1 and 3.3.1 and so should you. I tested with trunk from yesterday, but not very intensive. No Thaddy, I did not applied his patch, I downloaded version of 3.2.1 and compiled it. It already contains the patch.  Maybe I said it wrong. ---------------------------------------------------------------------- trev · 2021-01-25 23:59 I can confirm the issue with Lazarus 2.1 r64368 FPC 3.3.1 r48100 macOS 10.14.6 Xcode 11.3.1. Firefox on the other hand works OK. ---------------------------------------------------------------------- engkin · 2021-02-17 04:14 Quote from: Soner on January 24, 2021, 08:19:23 pmIt looks like your bugfix did not solve the bug. TFPHTTPClient still holds only last cookie in fpc 3.2.1-Svn 62267 and latest svn version.(My fpc  contains your bugfix). I uploaded  test project with server and httpclient app. Chrome- Browser holds cookie until it is closed, but TFPHTTPClient loses it after second call. Maybe you should open the bug report again. Hi Soner, Based on your test project, I think you missunderstood what this bug was about. Your test project sets/clears *one cookie*. The bug I fixed is related to having more than one cookie in the *same* response. A comment about THTTPClient.cookies in the source code: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i // Cookies. Set before request to send cookies to server.// After request the property is filled with the cookies sent by the server.Property Cookies : TStrings Read GetCookies Write SetCookies; You are supposed to set the cookies property every time before sending your request. Managing cookies is not part of THTTPClient, the property is a simple TStringList. At least in FPC 3.2.0 IIRC, FCL-Web comes with at least one example that shows how to retain cookies during multiple requests.