Skip to content

Commit 0d9d25f

Browse files
authored
Encourage redirect after POST (#80)
The Post/Redirect/Get design idiom https://en.wikipedia.org/wiki/Post/Redirect/Get is encouraged when the POST method is used to receive web share requests.
1 parent fc831cb commit 0d9d25f

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

level-2/index.html

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,8 +200,8 @@ <h2>
200200
event.respondWith((async () =&gt; {
201201
const formData = await event.request.formData();
202202
const link = formData.get('link') || '';
203-
saveBookmark(link);
204-
return new Response('Bookmark saved: ' + link);
203+
const responseUrl = await saveBookmark(link);
204+
return Response.redirect(responseUrl, 303);
205205
})());
206206
});
207207
</pre>
@@ -268,6 +268,12 @@ <h2>
268268
<code>url</code> with a short link to fit into the message size.
269269
</li>
270270
</ul>
271+
<p>
272+
As with HTML forms, replying to a POST request with a
273+
<a data-cite="!RFC7231#section-6.4.4">303 See Other</a> redirect
274+
is highly recommended, as it avoids the POST being submitted a
275+
second time if the user requests a page refresh.
276+
</p>
271277
</section>
272278
<section data-link-for="WebAppManifest">
273279
<h2>

0 commit comments

Comments
 (0)