Skip to content

Commit

Permalink
move header injection to FormSubmission
Browse files Browse the repository at this point in the history
  • Loading branch information
seanpdoyle committed Jan 28, 2021
1 parent ad6c0cf commit 4cb9fa1
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 12 deletions.
1 change: 1 addition & 0 deletions src/core/drive/form_submission.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ export class FormSubmission {
if (token) {
headers["X-CSRF-Token"] = token
}
headers["Accept"] = "text/vnd.turbo-stream.html"
}
return headers
}
Expand Down
12 changes: 0 additions & 12 deletions src/observers/stream_observer.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { FormSubmission } from "../core/drive/form_submission"
import { FetchResponse } from "../http/fetch_response"
import { StreamMessage } from "../core/streams/stream_message"
import { StreamSource } from "../core/types"
Expand All @@ -19,15 +18,13 @@ export class StreamObserver {
start() {
if (!this.started) {
this.started = true
addEventListener("turbo:submit-start", this.prepareFormSubmission, true)
addEventListener("turbo:before-fetch-response", this.inspectFetchResponse, false)
}
}

stop() {
if (this.started) {
this.started = false
removeEventListener("turbo:submit-start", this.prepareFormSubmission, true)
removeEventListener("turbo:before-fetch-response", this.inspectFetchResponse, false)
}
}
Expand All @@ -50,15 +47,6 @@ export class StreamObserver {
return this.sources.has(source)
}

prepareFormSubmission = <EventListener>((event: CustomEvent) => {
const formSubmission: FormSubmission = event.detail?.formSubmission
const headers: any = formSubmission.fetchRequest.fetchOptions.headers

if (headers) {
headers.Accept = [ "text/vnd.turbo-stream.html", headers.Accept ].join(", ")
}
})

inspectFetchResponse = <EventListener>((event: CustomEvent) => {
const response = fetchResponseFromEvent(event)
if (response && fetchResponseIsStream(response)) {
Expand Down

0 comments on commit 4cb9fa1

Please sign in to comment.