Assert on request headers only (#57792)

Only assert that actual request headers are empty, as default headers might still be there when stashing the context.
This commit is contained in:
Yannick Welsch 2020-06-09 14:07:17 +02:00
parent 2c6bd978d8
commit b5d3565214
2 changed files with 10 additions and 3 deletions

View File

@ -302,6 +302,13 @@ public final class ThreadContext implements Writeable {
return Collections.unmodifiableMap(map);
}
/**
* Returns the request headers, without the default headers
*/
public Map<String, String> getRequestHeadersOnly() {
return Collections.unmodifiableMap(new HashMap<>(threadLocal.get().requestHeaders));
}
/**
* Get a copy of all <em>response</em> headers.
*

View File

@ -62,9 +62,9 @@ public enum Transports {
}
public static boolean assertDefaultThreadContext(ThreadContext threadContext) {
assert threadContext.getHeaders().isEmpty() ||
threadContext.getHeaders().size() == 1 && threadContext.getHeaders().containsKey(Task.X_OPAQUE_ID) :
"expected empty context but was " + threadContext.getHeaders() + " on " + Thread.currentThread().getName();
assert threadContext.getRequestHeadersOnly().isEmpty() ||
threadContext.getRequestHeadersOnly().size() == 1 && threadContext.getRequestHeadersOnly().containsKey(Task.X_OPAQUE_ID) :
"expected empty context but was " + threadContext.getRequestHeadersOnly() + " on " + Thread.currentThread().getName();
return true;
}
}