-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: throw error if rewrite is attempted after body is used (#11258)
* fix: throw error if rewrite is attempted after body is used * Apply suggestions from code review Co-authored-by: Sarah Rainsberger <sarah@rainsberger.ca> --------- Co-authored-by: Sarah Rainsberger <sarah@rainsberger.ca>
- Loading branch information
1 parent
537e971
commit d996db6
Showing
7 changed files
with
97 additions
and
0 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,5 @@ | ||
--- | ||
'astro': patch | ||
--- | ||
|
||
Adds a new error `RewriteWithBodyUsed` that throws when `Astro.rewrite` is used after the request body has already been read. |
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
7 changes: 7 additions & 0 deletions
7
packages/astro/test/fixtures/rewrite-server/src/pages/post/index.astro
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,7 @@ | ||
--- | ||
--- | ||
|
||
<form method="post" action="/post/post-body-used"> | ||
<input type="text" name="email" value="example@example.com" /> | ||
<input type="submit" /> | ||
</form> |
15 changes: 15 additions & 0 deletions
15
packages/astro/test/fixtures/rewrite-server/src/pages/post/post-b.astro
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 @@ | ||
--- | ||
let email = '' | ||
if (Astro.request.method === 'POST') { | ||
try { | ||
const data = await Astro.request.formData(); | ||
email = data.get('email'); | ||
} catch (e) { | ||
console.log(e) | ||
} | ||
} | ||
--- | ||
|
||
<h1>Post B</h1> | ||
|
||
<h2>{email}</h2> |
17 changes: 17 additions & 0 deletions
17
packages/astro/test/fixtures/rewrite-server/src/pages/post/post-body-used.astro
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,17 @@ | ||
--- | ||
let data | ||
if (Astro.request.method === 'POST') { | ||
try { | ||
data = await Astro.request.text(); | ||
} catch (e) { | ||
console.log(e) | ||
} | ||
} | ||
return Astro.rewrite('/post/post-b') | ||
--- | ||
|
||
<h1>Post body used</h1> | ||
|
||
<h2>{data}</h2> |
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