Skip to content

Preserve connection keep-alive for JMeter compatibility#116

Merged
3dgiordano merged 2 commits into
developmentfrom
KEEPALIVE-IMPROVEMENTS
Jul 3, 2026
Merged

Preserve connection keep-alive for JMeter compatibility#116
3dgiordano merged 2 commits into
developmentfrom
KEEPALIVE-IMPROVEMENTS

Conversation

@3dgiordano

Copy link
Copy Markdown
Collaborator

Jetty does not preserve it because HTTP 1.1 do
This pull request introduces a new utility class to ensure that JMeter-visible request headers, such as the Connection header, are correctly preserved and reflected in HTTPSampleResult#getRequestHeaders(), even when Jetty omits or modifies them. It also adds comprehensive unit and integration tests to verify this behavior, and refactors the main HTTP client logic to use the new utility for consistent header handling.

Request header preservation and handling:

  • Added the new JmeterRequestHeadersSupport utility class to manage sampler-driven request headers, especially Connection: keep-alive and Connection: close, ensuring these are correctly recorded for JMeter samples even if Jetty omits or alters them on the wire.
  • Updated HTTP2JettyClient.java to use JmeterRequestHeadersSupport.prepareFromSampler and copySamplerHeaderState in relevant request preparation and fallback paths, ensuring consistent attribute and header propagation. [1] [2] [3]
  • Changed the logic for serializing request headers for sample results to use the headers as reconstructed by JmeterRequestHeadersSupport.headersForSampleResult, ensuring accurate reporting.

Testing improvements:

  • Added JmeterRequestHeadersSupportTest.java with unit tests for the new utility, verifying correct header preparation, restoration, and override behavior.
  • Added HttpKeepAliveSampleHeadersTest.java integration test to verify that the correct Connection header is present in sample results and on the wire, depending on the useKeepAlive setting.es not require it, but it is preserved for compatibility with JMeter.

Jetty does not preserve it because HTTP 1.1 does not require it, but it is preserved for compatibility with JMeter.
}
HttpFields.Mutable merged = HttpFields.build(request.getHeaders());
restoreConnectionHeaderForSample(request, merged);
// restoreEmptyUserAgentForSample(request, merged);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this dead code?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a placeholder for the next pull request.

It's part of a larger project that's out there somewhere.
There's another issue related to the User Agent, and I didn't want to include it in the same pull request, but the overall refactoring and implementation structure would encompass both. I've left the placeholder comments for the larger project; once this pull request is approved, the next one will follow.

@3dgiordano 3dgiordano merged commit 7318437 into development Jul 3, 2026
1 check passed
@3dgiordano 3dgiordano deleted the KEEPALIVE-IMPROVEMENTS branch July 3, 2026 12:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants