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
Recursively collect delegate headers to include in fetch request #110
Closed
Conversation
This file contains 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
tleish
force-pushed
the
add-all-headers-to-fetch-request
branch
from
January 31, 2021 14:05
f3d413a
to
9c8f35c
Compare
Updated code to support addition of |
seanpdoyle
added a commit
to seanpdoyle/turbo
that referenced
this pull request
Feb 7, 2021
Closes hotwired#86 Closes hotwired#110 Recursively walk the tree of dependent FetchRequestDelegates so that they all have an opportunity to modify the fetch request headers. Testing adds listeners for `turbo:before-fetch-request` and `turbo:before-fetch-response` so that the event logs can drain. Co-authored-by: tleish <tleish@users.noreply.github.com>
seanpdoyle
added a commit
to seanpdoyle/turbo
that referenced
this pull request
Feb 7, 2021
Closes hotwired#86 Closes hotwired#110 Recursively walk the tree of dependent FetchRequestDelegates so that they all have an opportunity to modify the fetch request headers. Testing adds listeners for `turbo:before-fetch-request` and `turbo:before-fetch-response` so that the event logs can drain. Co-authored-by: tleish <tleish@users.noreply.github.com>
seanpdoyle
added a commit
to seanpdoyle/turbo
that referenced
this pull request
Feb 7, 2021
Closes hotwired#86 Closes hotwired#110 When submitting a Form that is within a `<turbo-frame>` or targets a `<turbo-frame>`, ensure that the `Turbo-Frame` header is present. Testing adds listeners for `turbo:before-fetch-request` and `turbo:before-fetch-response` so that the event logs can drain. Co-authored-by: tleish <tleish@users.noreply.github.com>
seanpdoyle
added a commit
to seanpdoyle/turbo
that referenced
this pull request
Feb 7, 2021
Closes hotwired#86 Closes hotwired#110 When submitting a Form that is within a `<turbo-frame>` or targets a `<turbo-frame>`, ensure that the `Turbo-Frame` header is present. Since the constructive-style `FetchRequestDelegate.additionalHeadersForRequest()` was replaced by the mutative style `FetchRequestDelegate.prepareHeadersForRequest()`, this commit changes the `FetchRequest.headers` property to be `readonly` and created at constructor-time so that its values can be mutated prior to the request's submission. Testing adds listeners for `turbo:before-fetch-request` and `turbo:before-fetch-response` so that the event logs can drain. Co-authored-by: tleish <tleish@users.noreply.github.com>
seanpdoyle
added a commit
that referenced
this pull request
Feb 12, 2021
Closes #86 Closes #110 When submitting a Form that is within a `<turbo-frame>` or targets a `<turbo-frame>`, ensure that the `Turbo-Frame` header is present. Since the constructive-style `FetchRequestDelegate.additionalHeadersForRequest()` was replaced by the mutative style `FetchRequestDelegate.prepareHeadersForRequest()`, this commit changes the `FetchRequest.headers` property to be `readonly` and created at constructor-time so that its values can be mutated prior to the request's submission. Testing adds listeners for `turbo:before-fetch-request` and `turbo:before-fetch-response` so that the event logs can drain. Co-authored-by: tleish <tleish@users.noreply.github.com>
seanpdoyle
added a commit
that referenced
this pull request
Apr 9, 2021
Closes #86 Closes #110 When submitting a Form that is within a `<turbo-frame>` or targets a `<turbo-frame>`, ensure that the `Turbo-Frame` header is present. Since the constructive-style `FetchRequestDelegate.additionalHeadersForRequest()` was replaced by the mutative style `FetchRequestDelegate.prepareHeadersForRequest()`, this commit introduces a readonly `FetchRequestHeaders` property created at constructor-time so that its values can be mutated prior to the request's submission. Co-authored-by: tleish <tleish@users.noreply.github.com>
seanpdoyle
added a commit
to seanpdoyle/turbo
that referenced
this pull request
Apr 9, 2021
Closes hotwired#86 Closes hotwired#110 When submitting a Form that is within a `<turbo-frame>` or targets a `<turbo-frame>`, ensure that the `Turbo-Frame` header is present. Since the constructive-style `FetchRequestDelegate.additionalHeadersForRequest()` was replaced by the mutative style `FetchRequestDelegate.prepareHeadersForRequest()`, this commit introduces a readonly `FetchRequestHeaders` property created at constructor-time so that its values can be mutated prior to the request's submission. Co-authored-by: tleish <tleish@users.noreply.github.com>
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.
Closes #86
When turbo sends a fetch, it uses the following method in
FetchRequest
to get additional headers:When the
this.delegate=FrameController
, the FrameController adds theTurbo-Frame
header to the request.TURBO-FRAME GET
For a GET form inside. a turbo-frame,
this.delegate=FrameController
. So, form#GET requests include theTurbo-Frame
header.TURBO-FRAME NON-GET (e.g. POST/PUT/DELETE)
For a NON-GET form inside. a turbo-frame,
this.delegate=FrameController
. Which means, noTurbo-Frame
header.The system does detect the turbo-frame, it just wraps it in FormSubmission and assigns FrameController as the delegate.
FormSubmission = { delegate: FrameController }
Perhaps there are other nested delegate scenarios (e.g. ViewController). This update traverses delegates to collect all additionalHeadersForRequest. It also ensures that headers from the closest delegate relatives override headers from the most distance delegate relatives.