Skip to content

Instantly share code, notes, and snippets.

@andfanilo
Created June 10, 2020 07:32
Show Gist options
  • Save andfanilo/8c76ad86901f0e14c058603df15da1b9 to your computer and use it in GitHub Desktop.
Save andfanilo/8c76ad86901f0e14c058603df15da1b9 to your computer and use it in GitHub Desktop.
[Streamlit] Access request HTTP headers

streamlit/streamlit#1083 (comment)

from streamlit.server.Server import Server
import streamlit as st

def get_headers():
    # Hack to get the session object from Streamlit.

    current_server = Server.get_current()
    if hasattr(current_server, '_session_infos'):
        # Streamlit < 0.56
        session_infos = Server.get_current()._session_infos.values()
    else:
        session_infos = Server.get_current()._session_info_by_id.values()

    # Multiple Session Objects?
    for session_info in session_infos:
        headers = session_info.ws.request.headers
        st.write(headers)
#    return headers
@ahtokca
Copy link

ahtokca commented Sep 12, 2022

Thank a lit, @andfanilo

@andfanilo
Copy link
Author

You should now use the dedicated _get_websocket_headers() streamlit/streamlit#5457

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment