From 633e348ac4eb12ae650037d0f3364acff7a68f48 Mon Sep 17 00:00:00 2001 From: David Levin Date: Wed, 25 Feb 2026 20:31:35 -0800 Subject: [PATCH] Fix: getResponseHeaders() returns empty struct after setup() MockRequestContext.getResponseHeaders() always returns an empty struct {} in integration tests, even after calling setHTTPHeader() with named headers. This causes test assertions on response headers to fail unexpectedly when setup() is called between tests. --- .../mock/web/context/MockRequestContext.cfc | 2 ++ .../specs/web/context/RequestContextTest.cfc | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/system/testing/mock/web/context/MockRequestContext.cfc b/system/testing/mock/web/context/MockRequestContext.cfc index 9ce3ba013..4d450bf96 100644 --- a/system/testing/mock/web/context/MockRequestContext.cfc +++ b/system/testing/mock/web/context/MockRequestContext.cfc @@ -29,6 +29,8 @@ component else if ( structKeyExists( arguments, "name" ) ) { var headers = getValue( "cbox_headers", {} ); headers[ lCase( arguments.name ) ] = arguments.value; + // Keep variables.responseHeaders in sync so getResponseHeaders() works in tests + variables.responseHeaders[ arguments.name ] = arguments.value; setValue( "cbox_headers", headers ); } else { throw( diff --git a/tests/specs/web/context/RequestContextTest.cfc b/tests/specs/web/context/RequestContextTest.cfc index 5d30c36e0..f3541afcd 100755 --- a/tests/specs/web/context/RequestContextTest.cfc +++ b/tests/specs/web/context/RequestContextTest.cfc @@ -591,6 +591,25 @@ component extends="coldbox.system.testing.BaseModelTest" { event.setHTTPHeader( name = "expires", value = "#now()#" ); } + function testMockRequestContextPopulatesResponseHeaders(){ + // MockRequestContext.setHTTPHeader() should populate variables.responseHeaders + // so that getResponseHeaders() works correctly in integration tests + var mockEvent = getMockBox().createMock( "coldbox.system.testing.mock.web.context.MockRequestContext" ); + mockEvent.init( properties = props, controller = mockController ); + + // Set custom headers + mockEvent.setHTTPHeader( name = "x-custom-header", value = "test-value" ); + mockEvent.setHTTPHeader( name = "cached-data", value = "false" ); + + // getResponseHeaders() should return the headers that were set + var headers = mockEvent.getResponseHeaders(); + + expect( headers ).toHaveKey( "x-custom-header" ); + expect( headers[ "x-custom-header" ] ).toBe( "test-value" ); + expect( headers ).toHaveKey( "cached-data" ); + expect( headers[ "cached-data" ] ).toBe( "false" ); + } + function testGetHTTPContent(){ var event = getRequestContext(); test = event.getHTTPContent();