The Burp Suite User Forum was discontinued on the 1st November 2024.

Burp Suite User Forum

For support requests, go to the Support Center. To discuss with other Burp users, head to our Discord page.

SUPPORT CENTER DISCORD

messageEditorHttpRequestResponse cannot update multiple http headers

Wei | Last updated: May 14, 2024 09:29PM UTC

Hi there, I tried to use montoya to update 2 http headers messageEditorHttpRequestResponse.setRequest(messageEditorHttpRequestResponse.requestResponse().request().withUpdatedHeader("header1", "test1")); // messageEditorHttpRequestResponse.setRequest(messageEditorHttpRequestResponse.requestResponse().request().withUpdatedHeader("header2", "test2")); looks like it will ignore the first withUpdatedHeader and only update the header2.

Wei | Last updated: May 14, 2024 09:30PM UTC

messageEditorHttpRequestResponse.setRequest(messageEditorHttpRequestResponse.requestResponse().request().withUpdatedHeader("header1", "test1")); messageEditorHttpRequestResponse.setRequest(messageEditorHttpRequestResponse.requestResponse().request().withUpdatedHeader("header2", "test2"));

Wei | Last updated: May 14, 2024 10:01PM UTC

tried a couple of times, seems it only act the last action such as update header, add header etc.

Hannah, PortSwigger Agent | Last updated: May 15, 2024 03:24PM UTC

Hi

HttpRequests are immutable objects, so when you use a helper method like "withUpdatedHeader()" it will return a new object rather than making modifications to the existing one.

This means that the second time when you call messageEditorHttpRequestResponse.requestResponse().request(), you still receive back the original object and only the second header is set.

You can get around this by extracting the request into a variable, or inlining your method calls.

For example:
messageEditorHttpRequestResponse.setRequest(messageEditorHttpRequestResponse.requestResponse().request().withUpdatedHeader("header1", "test1").withUpdatedHeader("header2", "test2"));
or
HttpRequest request = messageEditorHttpRequestResponse.requestResponse().request().withUpdatedHeader("header1", "test1");
request = request.withUpdatedHeader("header2", "test2");

messageEditorHttpRequestResponse.setRequest(request);

Wei | Last updated: May 15, 2024 04:01PM UTC

awsome. Thank you so much Hannah! Inline method works!

Hannah, PortSwigger Agent | Last updated: May 16, 2024 08:56AM UTC