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

customized x-csrftoken contains extra undefined #3114

Open
CNFeffery opened this issue Dec 31, 2024 · 0 comments
Open

customized x-csrftoken contains extra undefined #3114

CNFeffery opened this issue Dec 31, 2024 · 0 comments
Labels
bug something broken P2 considered for next cycle

Comments

@CNFeffery
Copy link
Contributor

When customizing the x-csrftoken field for requests sent from the browser based on hooks, the actual field value obtained on the backend always contains extra undefined content. This issue does not occur when setting other fields.

Image

import dash
from dash import html
from flask import request
from dash.dependencies import Input, Output

app = dash.Dash(
    __name__,
    hooks={
        "request_pre": """
(payload) => {
    store.getState().config.fetch.headers['x-csrftoken'] = 'test-extra-header-value'
    store.getState().config.fetch.headers['other-field'] = 'other-value'
}
"""
    },
)

app.layout = html.Div(
    [html.Button("test", id="test-input"), html.Br(), html.Span(id="test-output")],
    style={"padding": 50},
)


@app.callback(Output("test-output", "children"), Input("test-input", "n_clicks"))
def test_callback(n_clicks):
    return "x-csrftoken: {}  other-field: {}".format(
        request.headers.get("x-csrftoken"), request.headers.get("other-field")
    )


if __name__ == "__main__":
    app.run(debug=True)
dash                 2.18.2
@gvwilson gvwilson changed the title [BUG] x-csrftoken with extra undefined customized x-csrftoken contains extra undefined Jan 3, 2025
@gvwilson gvwilson added bug something broken P2 considered for next cycle labels Jan 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug something broken P2 considered for next cycle
Projects
None yet
Development

No branches or pull requests

2 participants