Skip to content

Commit 2a7b35d

Browse files
committed
feat: PUT/DELETE requests do not need basic auth
1 parent f64741b commit 2a7b35d

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ user1 = "passwd1"
5757
user2 = "passwd2"
5858
```
5959

60-
Now every access to PUT or POST request, and every access to the index page, requires an HTTP basic auth with the user-password pair listed above. For example:
60+
Now every access to POST request, and every access to static pages, requires an HTTP basic auth with the user-password pair listed above. For example:
6161

6262
```shell
6363
$ curl example-pb.com

src/index.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,11 @@ async function handleNormalRequest(request, env, ctx) {
6161
}
6262

6363
async function handlePostOrPut(request, env, ctx, isPut) {
64-
const authResponse = verifyAuth(request, env)
65-
if (authResponse !== null) {
66-
return authResponse
64+
if (!isPut) { // only POST requires auth, since PUT request already contains auth
65+
const authResponse = verifyAuth(request, env)
66+
if (authResponse !== null) {
67+
return authResponse
68+
}
6769
}
6870

6971
const contentType = request.headers.get("content-type") || ""

0 commit comments

Comments
 (0)