Skip to content

Conversation

kevin-bates
Copy link
Member

Fixes: #1557

This pull request addresses two issues:

  1. When multiple Set-Cookies are returned from the Gateway server and accessed via response.headers.get("Set-Cookie"), the cookies are returned in a comma-separated string. The SimpleCookie.load() method fails to parse this string, and the exception listed in GatewayClient doesn't correctly handle multiple cookies returned from gateway server #1557 is raised.
  2. The pytest to test cookie handling, in particular the one related to expiration, was not working correctly because it was producing an expires morsel with an tz offset (e.g., +0000) rather than the tz name (e.g., GMT) and, again, SimpleCookie.load() did not parse that. The test still passed because the "expiring" cookie was not present, but it wasn't present due to the parsing issue and not because it was caught as expired.

Issue 1 has been addressed by using response.headers.get_list("Set-Cookie"), where each element (cookie) in the list is loaded and processed.

Issue 2 has been addressed by using a date formatter that produces an RFS 7231-compliant date string, and the use of the email.utils package has been removed. The test has also been refactored to be clearer when expiration testing is performed. This led to the removal of one of the test's arguments since it was rendered obsolete by the refactoring.

Lastly, the call to the gateway_client.update_cookies() method has been updated to improve testability.

@kevin-bates kevin-bates force-pushed the fix-gateway-cookie-handling branch 2 times, most recently from 1cb64b9 to 0cc8523 Compare August 29, 2025 18:58
@kevin-bates kevin-bates force-pushed the fix-gateway-cookie-handling branch 3 times, most recently from aa72183 to 188b5ca Compare August 29, 2025 19:18
@kevin-bates
Copy link
Member Author

I'm sorry, but I don't understand the linting failure. Please advise.

Copy link
Contributor

@RRosio RRosio left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi Kevin! I'm not that familiar with the jupyter_server codebase but I took a quick look at the failing CI so I wanted to add some comments!

@kevin-bates kevin-bates force-pushed the fix-gateway-cookie-handling branch from 89d7e29 to bf15cef Compare September 1, 2025 15:38
@kevin-bates
Copy link
Member Author

Hmm - bit of a catch-22 here as best as I can determine.

This linting error suggests I move the import into a type-checking block:

jupyter_server/gateway/gateway_client.py:21:30: TCH002 Move third-party import `tornado.httputil.HTTPHeaders` into a type-checking block

But when I do that, the docs build fails with:

WARNING: Cannot resolve forward reference in type annotations of "jupyter_server.gateway.gateway_client.GatewayClient.update_cookies": name 'HTTPHeaders' is not defined

So I reverted the change, and am back to the lint error.

With the change reverted, the type checks, linting, tests, and docs build pass on my dev machine. Could someone please let me know how I should proceed? Thank you.

@kevin-bates
Copy link
Member Author

This has been driving me crazy. I think it's more important to keep the type defined (i.e., not use the TYPE_CHECKING hint). This enables the docs build to succeed. The type hint suggested by TCH002 appears to allow for the elimination of an import at runtime, but given this is a long-running server that additional import is not costly in the grand scheme of things (and assuming I'm understanding the topic). As a result, I decided to add an "ignores" entry of "TCH" issues for the gateway files (for now) - which the tests also ignore (i.e., precedent).

At least this should allow us to get past the TCH002 issue, which I believe might be an example of a false positive, or at least in direct conflict with what the docs build requires.

@kevin-bates kevin-bates requested a review from lresende September 8, 2025 14:09
@kevin-bates
Copy link
Member Author

Could I please get this reviewed. Since it's gateway related I requested @lresende but the general list of reviewers looks extremely old and I don't think it reflects the current team membership. Thanks.

@lresende
Copy link
Member

lresende commented Sep 8, 2025

Thank you for taking care of this @kevin-bates

@kevin-bates
Copy link
Member Author

Hello @vidartf and @Zsailer - I hope you're doing well.

Could I please ask that this PR be merged? I'd love to see it released soon as well, but so long as it makes the next train out of town, that would be great.

@minrk minrk merged commit 8f99062 into jupyter-server:main Sep 18, 2025
37 checks passed
@kevin-bates
Copy link
Member Author

Thank you for the merge @minrk!

@kevin-bates
Copy link
Member Author

@vidartf, @minrk, @Zsailer - are there plans for cutting a release soon? Seems like a good target would be early November (i.e., JupyterCon).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

GatewayClient doesn't correctly handle multiple cookies returned from gateway server
4 participants