Add hx-vals support along with configurable SSE (POST + Auth)/WS connections#188
Open
XChikuX wants to merge 1 commit into
Open
Add hx-vals support along with configurable SSE (POST + Auth)/WS connections#188XChikuX wants to merge 1 commit into
XChikuX wants to merge 1 commit into
Conversation
…sts and docs Agent-Logs-Url: https://github.com/XChikuX/htmx-extensions/sessions/276ae3c0-c984-43d2-9286-fa4a1845c56b Co-authored-by: XChikuX <5894493+XChikuX@users.noreply.github.com>
✅ Deploy Preview for htmx-extensions canceled.
|
Author
|
Full Discosure:
PR passes existing tests, as well as additional tests added for both SSE and WS. I reviewed the changes and they seem minimally invasive with useful additions. It should close all the mentioned issues above. @Telroshan @adonespitogo @GrimalDev @bradleyjkemp @elieobeid7 Please let me know if there are any concerns with code quality. Recommended SSE polyfill: https://github.com/mpetazzoni/sse.js/ (Apache 2.0 license) Possible future additions to this PR: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This update enhances the SSE and WS extensions to provide full control over the connection request, addressing limitations regarding query parameters, custom headers, and polyfill integration for methods like POST.
Description
Previously, the SSE and WS extensions offered no mechanism to influence the connection handshake, making it impossible to pass
hx-valsas query parameters (#34), injectAuthorizationheaders (#132), or supportPOST-capable polyfills likesse.js(#139, #143).Changes:
hx-valshandling:ensureEventSourcenow collectshx-vals/hx-varsviaapi.getExpressionVarsand appends them (URL-encoded) to the connect URL.htmx:sseConfigConnect&htmx:wsConfigConnect: New cancelable events fired before connection creation. Handlers can modify the URL, mutate options, or callpreventDefault()to abort.htmx.createEventSourceAPI: The signature is extended to pass anoptionsobject, allowing polyfills to receivemethod,headers, andpayload.sse.jsintegration.Example: POST SSE connection with Authorization header via sse.js
Htmx version: Latest
Used extension(s) version(s): SSE, WS
Corresponding issue: #34, #132, #139, #143
Testing
hx-valsare correctly appended to the URL and that thehtmx:sseConfigConnectevent correctly intercepts the connection lifecycle.Checklist
npm run test) and verified that it succeeded