needle icon indicating copy to clipboard operation
needle copied to clipboard

Fix multiple cookies for follow_set_cookies

Open QuiteQuiet opened this issue 2 years ago • 2 comments

It appears that cookies.js expects the format ofthe Set Cookies header to function. This sounds reasonable, but the original request's cookies are stored as a string (for convenience I believe?) not as key-value pair strings, so it needs to be separated again to be forwarded correctly in the redirect.

Fixes #350.

QuiteQuiet avatar Feb 08 '23 20:02 QuiteQuiet

Could you please add some tests? It looks to me this would break if the cookies header is empty...

tomas avatar Dec 08 '23 13:12 tomas

You are right it fails if there are no cookies... I think this should work instead?

There is already a test for an exmpty cookie with redirect, but I added one for multiple request cookies anyway.

I can't actually run all tests because I don't have access to a Linux machine which could, but all cookies-related tests are passing.

  cookies
    with default options
      √ no cookie header is set on request
(node:7320) [DEP0066] DeprecationWarning: OutgoingMessage.prototype._headers is deprecated
    if response does not contain cookies
      √ response.cookies is undefined
    if response contains cookies
      √ puts them on resp.cookies
      √ parses them as a object
      √ must decode it
      when a cookie value is invalid
        √ doesnt blow up
      and response is a redirect
        and follow_set_cookies is false
          with original request cookie
            √ request cookie is not passed to redirects
            √ response cookies are not passed either
          without original request cookie
            √ no request cookies are sent
            √ response cookies are not passed either
        and follow_set_cookies is true
          with original request cookie
            √ request cookie is passed passed to redirects, and response cookies are added too
            √ response cookies are passed as well
          with multiple original request cookies
            √ request cookie is passed passed to redirects, and response cookies are added too
            √ response cookies are passed as well
          without original request cookie
            √ response cookies are passed to redirects
            √ response cookies are passed as well
      with parse_cookies = false
        √ does not parse them
    if request contains cookie header
      √ must be a valid cookie string
      √ dont have to encode allowed characters
      √ must encode forbidden characters

QuiteQuiet avatar Jan 07 '24 15:01 QuiteQuiet