-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move X-HTTP-Method-Override out to an extension
fixes #86
- Loading branch information
carson
committed
Jun 10, 2020
1 parent
86f1334
commit 2305aed
Showing
12 changed files
with
102 additions
and
109 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
htmx.defineExtension('method-override', { | ||
onEvent: function (name, evt) { | ||
if (name === "configRequest.htmx") { | ||
var method = evt.detail.verb; | ||
if (method !== "get" || method !== "post") { | ||
evt.detail.headers['X-HTTP-Method-Override'] = method.toUpperCase(); | ||
evt.detail.verb = "post"; | ||
} | ||
} | ||
} | ||
}); |
This file was deleted.
Oops, something went wrong.
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
describe("method-override extension", function(){ | ||
beforeEach(function() { | ||
this.server = makeServer(); | ||
clearWorkArea(); | ||
}); | ||
afterEach(function() { | ||
this.server.restore(); | ||
clearWorkArea(); | ||
}); | ||
|
||
it('issues a DELETE request with proper headers', function() | ||
{ | ||
this.server.respondWith("DELETE", "/test", function(xhr){ | ||
xhr.requestHeaders['X-HTTP-Method-Override'].should.equal('DELETE'); | ||
xhr.method.should.equal("POST") | ||
xhr.respond(200, {}, "Deleted!"); | ||
}); | ||
|
||
var btn = make('<button hx-ext="method-override" hx-delete="/test">Click Me!</button>') | ||
btn.click(); | ||
this.server.respond(); | ||
btn.innerHTML.should.equal("Deleted!"); | ||
}); | ||
|
||
it('issues a PATCH request with proper headers', function() | ||
{ | ||
this.server.respondWith("PATCH", "/test", function(xhr){ | ||
xhr.requestHeaders['X-HTTP-Method-Override'].should.equal('PATCH'); | ||
xhr.method.should.equal("POST") | ||
xhr.respond(200, {}, "Patched!"); | ||
}); | ||
|
||
var btn = make('<button hx-ext="method-override" hx-patch="/test">Click Me!</button>') | ||
btn.click(); | ||
this.server.respond(); | ||
btn.innerHTML.should.equal("Patched!"); | ||
}); | ||
|
||
it('issues a PUT request with proper headers', function() | ||
{ | ||
this.server.respondWith("PUT", "/test", function(xhr){ | ||
xhr.requestHeaders['X-HTTP-Method-Override'].should.equal('PUT'); | ||
xhr.method.should.equal("POST") | ||
xhr.respond(200, {}, "Putted!"); | ||
}); | ||
|
||
var btn = make('<button hx-ext="method-override" hx-put="/test">Click Me!</button>') | ||
btn.click(); | ||
this.server.respond(); | ||
btn.innerHTML.should.equal("Putted!"); | ||
}); | ||
|
||
}) |
This file was deleted.
Oops, something went wrong.
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
--- | ||
layout: layout.njk | ||
title: </> htmx - high power tools for html | ||
--- | ||
|
||
## The `method-override` Extension | ||
|
||
This extension makes non-`GET` and `POST` requests use a `POST` with the `X-HTTP-Method-Override` header set to the | ||
actual HTTP method. This is necessary when dealing with some firewall or proxy situations. | ||
|
||
#### Usage | ||
|
||
```html | ||
<body hx-ext="method-override"> | ||
<button hx-put="/update"> | ||
This request will be made as a POST w/ the X-HTTP-Method-Override Header Set | ||
</button> | ||
</body> | ||
``` | ||
|
||
#### Source | ||
|
||
<https://unpkg.com/htmx.org/dist/ext/method-override.js> | ||
|
This file was deleted.
Oops, something went wrong.