Files
bruno/packages/bruno-tests/hooks-comprehensive-tests/hooks/beforeRequest/before-request-modify-request.bru
sanish-bruno 4bb01ca0ac feat: hooks runtime
add: hooks component

add support for hooks within bruno-lang

fix: hooks is not getting save

hooks implemtation

add hooks component within folders, requests

add: quick js shims for hooks

fix: garbage collected hook managers

send logs to main

rm: hook manager store

feat: introduce HOOK_EVENTS constant for improved hook management

add folder start/end events

add folder run events

rm: folder run related events

add cli support for hooks

support script:hooks instead of hooks

move hooks to script tab

make outer scope available within callback in safemode

added runner, req apis as an abstraction over event based hooks

fix: crash while editing folder hooks

rm: unused files

fix: self review changes

refactor, request specific hook manager deleted once

add: cm

rm: spaces

add prompt var

rm: indent

fix: lint

refactor: shims handling for hooks

fix: enable async calling in dev mode for gui, cli

fix: support async callbacks within safe mode

rm: vm instance

fix: review comments

fix: review comments

add cli tests for hooks

rm: client certs

fix: add hooks to oc yaml

fix: rename uid ot path name for better clarity, app crash when saving folder hooks

rm: console

rm: vm2 runtime leftover

rm: check

add: handler cleanup function

add: playwright test case for hooks

rm: review fixes

fix: review comments

add fallback hook manager

add fallback hook manager

fix: show error from hooks scripts within response pane

change: collection events name

feat: add name spaced hooks

fix: review comments

add: hooks specific collection for testing

use hooks manager as a private field

fix: tests

use collection from bruno-test within playwright

rm: databuffer test

fix: playwright test

rm: unintended changes

rm: file
2026-01-28 19:13:57 +05:30

46 lines
1.1 KiB
Plaintext

meta {
name: before-request-modify-request
type: http
seq: 1
}
get {
url: {{host}}/ping
body: none
auth: none
}
script:hooks {
bru.hooks.http.onBeforeRequest(({ req }) => {
console.log('[beforeRequest] Original URL:', req.getUrl());
console.log('[beforeRequest] Original method:', req.getMethod());
// Test: Modify URL
const originalUrl = req.getUrl();
req.setUrl(originalUrl + '?modified=true');
// Test: Modify headers
req.setHeader('X-Modified-By', 'beforeRequest-hook');
req.setHeader('X-Original-URL', originalUrl);
// Test: Get existing headers
const existingHeaders = req.getHeaders();
bru.setVar('header-count', Object.keys(existingHeaders).length.toString());
console.log('[beforeRequest] Modified URL:', req.getUrl());
});
}
tests {
test("request should have been modified by hook", function() {
// Verify hook executed
const headerCount = bru.getVar('header-count');
expect(parseInt(headerCount)).to.be.at.least(2);
});
test("response should be successful", function() {
expect(res.getStatus()).to.equal(200);
});
}