Skip to content

Instantly share code, notes, and snippets.

@BirnadinErick
Created November 22, 2023 11:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BirnadinErick/ddb97f05824f901c0a96928d363264b5 to your computer and use it in GitHub Desktop.
Save BirnadinErick/ddb97f05824f901c0a96928d363264b5 to your computer and use it in GitHub Desktop.
HTTP 302 vs 303 Code listing
<html>
<head>
<title>302 and 303 Diff Demo</title>
</head>
<body>
<h1>SUTBLE Difference between Redirect 302 and 303</h1>
<button hx-delete="/302" hx-target="next #target" hx-swap="innerHTML" type="button">
issue request to 302
</button>
<button hx-delete="/303" hx-target="next #target" hx-swap="innerHTML" type="button">
issue request to 303
</button>
<div id="target" style="margin-top: 10px;">
</div>
<script src="https://unpkg.com/htmx.org@1.9.9"
integrity="sha384-QFjmbokDn2DjBjq+fM+8LUIVrAgqcNW2s0PjAxHETgRn9l4fvX31ZxDxvwQnyMOX"
crossorigin="anonymous"></script>
</body>
</html>
const server = Bun.serve({
port: 2003,
fetch(req) {
const url = new URL(req.url);
switch (url.pathname) {
case "/":
console.log("root access");
return new Response(Bun.file("./index.html"))
case "/302":
console.log("302 endpoint");
// 302 is the default behavior of `redirect`
return Response.redirect("/end");
case "/303":
console.log("303 endpoint");
return Response.redirect("/end", 303);
case "/end":
return new Response(`endpoint hit with HTTP method ${req.method}`);
default:
return new Response("404")
}
},
});
console.log(`Listening on http://localhost:${server.port} ...`);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment