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 3, 2021
1 parent 3e51ffd commit b7a1187
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 13 deletions.
2 changes: 1 addition & 1 deletion src/core/drive/form_submission.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ export class FormSubmission {
// Fetch request delegate

additionalHeadersForRequest(request: FetchRequest) {
const headers: FetchRequestHeaders = {}
const headers: FetchRequestHeaders = { Accept: "text/html; turbo-stream" }
if (this.method != FetchMethod.get) {
const token = getCookieValue(getMetaContent("csrf-param")) || getMetaContent("csrf-token")
if (token) {
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/html; turbo-stream", headers.Accept ].join(", ")
}
})

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

0 comments on commit b7a1187

Please sign in to comment.