mirror of
https://github.com/usebruno/bruno.git
synced 2026-06-11 09:51:30 +00:00
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:
@@ -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"
|
||||
);
|
||||
|
||||
|
||||
@@ -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');
|
||||
|
||||
33
packages/bruno-tests/src/mix/index.js
Normal file
33
packages/bruno-tests/src/mix/index.js
Normal 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;
|
||||
@@ -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;
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user