Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only update response headers if we have a new one #37590

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,17 @@ public void addResponseHeader(final String key, final String value) {
* @param uniqueValue the function that produces de-duplication values
*/
public void addResponseHeader(final String key, final String value, final Function<String, String> uniqueValue) {
threadLocal.set(threadLocal.get().putResponse(key, value, uniqueValue, maxWarningHeaderCount, maxWarningHeaderSize));
/*
* Updating the thread local is expensive due to a shared reference that we synchronize on, so we should only do it if the thread
* context struct changed. It will not change if we de-duplicate this value to an existing one, or if we don't add a new one because
* we have reached capacity.
*/
final ThreadContextStruct current = threadLocal.get();
final ThreadContextStruct maybeNext =
current.putResponse(key, value, uniqueValue, maxWarningHeaderCount, maxWarningHeaderSize);
if (current != maybeNext) {
threadLocal.set(maybeNext);
}
}

/**
Expand Down