Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add http_cookie to WebsocketSession and UserSession #1653

Merged

Conversation

5enxia
Copy link
Contributor

@5enxia 5enxia commented Jan 9, 2025

This is a partial solution to this issue. #1213

Adding access to http_cookie to WebSocketSession and UserSession facilitates the use of chainlit in enterprise applications that deploy multiple services under the same domain.

Pull Request Summary

This pull request introduces support for handling HTTP cookies in the backend/chainlit module. The changes primarily involve adding a new http_cookie parameter to various methods and ensuring that this parameter is properly propagated throughout the session handling and testing code.

Session handling updates:

Testing updates:

@dosubot dosubot bot added size:S This PR changes 10-29 lines, ignoring generated files. backend Pertains to the Python backend. enhancement New feature or request labels Jan 9, 2025
@5enxia
Copy link
Contributor Author

5enxia commented Jan 10, 2025

How to check (with Chrome)

Frontend

  1. Open Browser Developer Tools.
  2. Select the Application tab.
  3. Select the relevant domain from Storage → Cookies.
  4. Add the following cookie:
  • Name: foo
  • Value: bar

Or run the following command in the Console tab:

document.cookie = "foo=bar;"

Backend

Please write below code in chainlit's entry file. (ex: hello.py)
And check log.

# This is a simple example of a chainlit app.
from chainlit import AskUserMessage, Message, on_chat_start
import chainlit as cl

# logger
import logging
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)

@on_chat_start
async def main():
    http_cookie = cl.user_session.get("http_cookie")
    logger.info(f"http_cookie: {http_cookie}")

    res = await AskUserMessage(content="What is your name?", timeout=30).send()
    if res:
        await Message(
            content=f"Your name is: {res['output']}.\nChainlit installation is working!\nYou can now start building your own chainlit apps!",
        ).send()

@willydouhard
Copy link
Collaborator

Thank you for your contribution!

@willydouhard willydouhard merged commit 25489c6 into Chainlit:main Jan 10, 2025
9 checks passed
@5enxia
Copy link
Contributor Author

5enxia commented Jan 10, 2025

Thank you for review and merge!

dokterbob pushed a commit to SynergyOS-ai/chainlit that referenced this pull request Jan 14, 2025
)

Co-authored-by: Willy Douhard <willy.douhard@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backend Pertains to the Python backend. enhancement New feature or request size:S This PR changes 10-29 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants