Files
bruno/packages/bruno-tests/src/index.js
Chirag Chandrashekhar 5e1a36f8c8 fix: close previous SSE connection before sending new request (#7474)
* fix: update system proxy fetching to use finally (#7652)

* fix: update system proxy fetching to use finally for improved reliability

* Update packages/bruno-electron/src/index.js

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

---------

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* fix: allow file selection in multipart form without entering a key first (#7640)

* fix: close previous SSE connection before sending new request

When resending an SSE (Server-Sent Events) request using Cmd+Enter,
the previous connection was not being closed, causing connection leaks.

Changes:
- Add SSE cancellation logic to sendRequest action - checks for running
  stream and cancels it before sending new request
- Add return to cancelRequest action to make it properly chainable
- Simplify RequestTabPanel by removing duplicate cancel logic (now
  handled centrally in sendRequest)
- Add SSE endpoints to test server for e2e testing
- Add Playwright e2e test to verify SSE connection cancellation

* fix: address PR review feedback for SSE connection cancellation

- Use platform-aware modifier (Meta on macOS, Control on Linux/Windows)
  instead of hardcoded Meta+Enter for cross-platform CI compatibility
- Replace waitForTimeout with expect.poll for deterministic assertions
- Remove dead try/catch around cancelRequest (errors already swallowed
  by cancelRequest's internal .catch)

* fix: updated the test to check of connectionIds

---------

Co-authored-by: Sid <siddharth@usebruno.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Pooja <pooja@usebruno.com>
Co-authored-by: Chirag Chandrashekhar <cchirag85@gmail.com>
2026-04-03 01:59:11 +05:30

84 lines
2.3 KiB
JavaScript

const express = require('express');
const bodyParser = require('body-parser');
const cors = require('cors');
const formDataParser = require('./multipart/form-data-parser');
const authRouter = require('./auth');
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 setupGraphQL = require('./graphql');
const sseRouter = require('./sse');
const app = new express();
const port = process.env.PORT || 8081;
app.use(cors());
const saveRawBody = (req, res, buf) => {
req.rawBuffer = Buffer.from(buf);
req.rawBody = buf.toString();
};
app.use(bodyParser.json({ verify: saveRawBody }));
app.use(bodyParser.urlencoded({ extended: true, verify: saveRawBody }));
app.use(bodyParser.text({ verify: saveRawBody }));
app.use(xmlParser());
// Only parse raw body for content types not already handled by other parsers
app.use(express.raw({
type: (req) => {
const contentType = req.headers['content-type'] || '';
// Skip if already handled by json, urlencoded, text, or xml parsers
if (contentType.includes('application/json')
|| contentType.includes('application/x-www-form-urlencoded')
|| contentType.includes('text/')
|| contentType.includes('application/xml')) {
return false;
}
return true;
},
limit: '100mb',
verify: saveRawBody
}));
formDataParser.init(app, express);
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.use('/api/sse', sseRouter);
app.get('/ping', function (req, res) {
return res.send('pong');
});
app.get('/headers', function (req, res) {
return res.json(req.headers);
});
app.get('/query', function (req, res) {
return res.json(req.query);
});
app.get('/redirect-to-ping', function (req, res) {
return res.redirect('/ping');
});
const server = require('http').createServer(app);
server.on('upgrade', wsRouter);
setupGraphQL(app).then(() => {
server.listen(port, function () {
console.log(`Testbench started on port: ${port}`);
});
})
.catch((error) => {
console.error('Failed to initialize GraphQL', error);
process.exit(1);
});