Using HTTP response headers in subsequent hx-get requests
Heya, awesome project which has really opened up web development for me :-)
I'm wondering if it's possible to re-use response header values in downstream AJAX requests. I'm using a Python/Flask backend and passing an index page to clients which has two divs lazy loaded using hx-get with hx-trigger.
E.g. <div id="my_stuff" hx-get="/get-stuff" hx-trigger="load" hx-swap="innerHTML">
I'm using a tool to perform application tracing which injects a custom HTTP header to associate requests/transactions so i'd like to be able to take the dynamic x-tracingtool-trace-id header/value which I get as a response for the GET on the index page, and pass it to the AJAX requests somehow.
There is a hx-headers attribute that i've tried but it seems limited to static values. I've managed to create the header with dummy values (e.g. hx-headers='{"x-tracingtool-trace-id": "test"}') but it needs the dynamic trace ID pulled from the initial response. There is a reference to using javascript to evaluate the values given in the documentation, but it isn't quite clear what 'evaluation' means or examples with the precise syntax.
I've looked at getting the value within Flask and rendering it in my jinja templates (which would obviously then work using hx-headers), but the trace header value isn't generated until well after the templates are rendered, so I can't simply pass it in like i've seen a lot of Django examples do with CSRF tokens.
Hello there,
First of all: is this issue still relevant to you?
Regarding your question about evaluated of hx-headers:
an example can be found in the tests, and gives you an idea of what it would look like on your use case: <div hx-headers="javascript:\"x-tracingtool-trace-id\": getLatestTraceId()"> where getLatestTraceId() would be a function in charge of reading a JS variable that you would write when receiving an HTTP response.
Am I making sense to you here?