-
Notifications
You must be signed in to change notification settings - Fork 296
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Upper case all http methods in fetch API with compat flag (#2913)
- Loading branch information
Showing
7 changed files
with
73 additions
and
8 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
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 @@ | ||
import { strictEqual, throws } from 'assert'; | ||
|
||
// Test depends on the setting of the upper_case_all_http_methods compatibility flag. | ||
strictEqual( | ||
globalThis.Cloudflare.compatibilityFlags['upper_case_all_http_methods'], | ||
true | ||
); | ||
|
||
export const test = { | ||
test() { | ||
// Verify that lower-cased method names are converted to upper-case. | ||
// even though the Fetch API doesn't do this in general for all methods. | ||
// Note that the upper_case_all_http_methods compat flag is intentionally | ||
// diverging from the Fetch API here. | ||
const req = new Request('https://example.com', { method: 'patch' }); | ||
strictEqual(req.method, 'PATCH'); | ||
|
||
// Unrecognized methods error as expected, with the error message | ||
// showing the original-cased method name. | ||
throws(() => new Request('http://example.org', { method: 'patchy' }), { | ||
message: /^Invalid HTTP method string: patchy$/, | ||
}); | ||
}, | ||
}; |
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,15 @@ | ||
using Workerd = import "/workerd/workerd.capnp"; | ||
|
||
const unitTests :Workerd.Config = ( | ||
services = [ | ||
( name = "fetch-test", | ||
worker = ( | ||
modules = [ | ||
(name = "worker", esModule = embed "fetch-test.js") | ||
], | ||
compatibilityDate = "2024-10-01", | ||
compatibilityFlags = ["nodejs_compat", "upper_case_all_http_methods"], | ||
) | ||
), | ||
], | ||
); |
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