fix: httpbun dependencies removed (#6041)

* fix: standardize URL formatting in insomnia test files

* feat: add mix router for handling custom redirects and cookies

* fix: add validation for redirect count to prevent infinite loops

* fix: update test URLs to use local server and add query parameters for improved testing
This commit is contained in:
Abhishek S Lal
2025-11-07 21:55:33 +05:30
committed by GitHub
parent 57c08350b6
commit 3fe5299d8e
5 changed files with 49 additions and 3 deletions

View File

@@ -5,16 +5,22 @@ meta {
}
get {
url: https://httpbun.com/mix/s=302/c=foo:bar/r=https%3A%2F%2Fhttpbun.org%2Fget
url: http://localhost:8081/api/mix?s=302&c=foo:bar&r=http://127.0.0.1:8081/query
body: none
auth: inherit
}
params:query {
s: 302
c: foo:bar
r: http://127.0.0.1:8081/query
}
tests {
const jar = bru.cookies.jar()
const cookieData = await jar.getCookie(
"https://httpbun.com",
"http://localhost:8081",
"foo"
);

View File

@@ -7,6 +7,7 @@ const echoRouter = require('./echo');
const xmlParser = require('./utils/xmlParser');
const multipartRouter = require('./multipart');
const redirectRouter = require('./redirect');
const mixRouter = require('./mix');
const wsRouter = require('./ws');
const app = new express();
@@ -31,6 +32,7 @@ app.use('/api/auth', authRouter);
app.use('/api/echo', echoRouter);
app.use('/api/multipart', multipartRouter);
app.use('/api/redirect', redirectRouter);
app.use('/api/mix', mixRouter);
app.get('/ping', function (req, res) {
return res.send('pong');

View File

@@ -0,0 +1,33 @@
const express = require('express');
const router = express.Router();
router.get('/', function (req, res) {
// Parse query parameters similar to http bun's /mix endpoint
// s=status code, c=cookie (name:value), r=redirect URL
const statusCode = parseInt(req.query.s, 10) || 302;
const cookie = req.query.c; // format: name:value
const redirectUrl = req.query.r;
// Set cookie if provided
if (cookie) {
const [cookieName, cookieValue] = cookie.split(':');
if (cookieName && cookieValue) {
res.setHeader('Set-Cookie', `${cookieName}=${cookieValue}; Path=/`);
}
}
// Redirect to the specified URL, even if it's not on our domain
if (redirectUrl) {
res.status(statusCode)
.set('Location', redirectUrl)
.send(`<!doctype html>
<title>Redirecting...</title>
<h1>Redirecting...</h1>
<p>You should be redirected automatically to target URL: <a href="${redirectUrl}">${redirectUrl}</a>. If not click the link.</p>
`);
} else {
res.status(400).json({ error: 'Missing redirect URL parameter (r)' });
}
});
module.exports = router;

View File

@@ -106,6 +106,11 @@ router.get('/anything', function (req, res) {
router.get('/:count', function (req, res) {
const count = parseInt(req.params.count, 10);
// Validate that count is a valid number to prevent infinite redirect loops
if (isNaN(count)) {
return res.status(404).json({ error: 'Invalid redirect count. Must be a number.' });
}
if (count > 1) {
// Redirect to the next redirect in the chain
const nextCount = count - 1;

View File

@@ -5,7 +5,7 @@ meta {
}
get {
url: https://httpbun.com/redirect/2
url: https://testbench-sanity.usebruno.com/redirect-to-ping
body: none
auth: inherit
}