Skip to content

Adopt Fetch API's Headers interface#3885

Open
scriptogre wants to merge 1 commit into
bigskysoftware:four-devfrom
scriptogre:4.0/headers
Open

Adopt Fetch API's Headers interface#3885
scriptogre wants to merge 1 commit into
bigskysoftware:four-devfrom
scriptogre:4.0/headers

Conversation

@scriptogre

Copy link
Copy Markdown
Collaborator

Replace the request header plain object with a native Headers instance.

Updates request building, hx-config, hx-headers, htmx.ajax(), and bundled extensions to use the standard Headers API.

HCON.merge(...) now knows how to merge into Headers, so existing object-style config values still work:

<div hx-config="headers.X-Custom: value"></div>

Added an hx-compat-htmx-4-beta auto-registered extension that keeps ctx.request.headers[name] working and warns with the new syntax:

[htmx] Deprecated: replace ctx.request.headers[name] with Headers methods 
  old: ctx.request.headers[name]
  new: ctx.request.headers.get(name), .set(name, value), or .delete(name)
  docs: https://developer.mozilla.org/en-US/docs/Web/API/Headers

The extension might seem a bit overengineered for what it does now, but it was done to cleanly accommodate some other stuff I'll propose in a PR soon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant