Skip to content

refactor: add copy constructor to request context #65

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

Merged
merged 1 commit into from
Nov 18, 2024
Merged
Show file tree
Hide file tree
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 @@ -33,6 +33,12 @@ public class RequestContext {
public static final Context.Key<RequestContext> CURRENT = Context.key("request_context");
private static final JwtParser JWT_PARSER = new JwtParser();

public RequestContext() {}

public RequestContext(RequestContext otherContext) {
this.headers.putAll(otherContext.headers);
}

public static RequestContext forTenantId(String tenantId) {
return new RequestContext()
.put(RequestContextConstants.TENANT_ID_HEADER_KEY, tenantId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,15 @@ void testGetRequestHeaders() {
requestHeaders);
}

@Test
void testCopyConstructor() {
RequestContext originalContext = new RequestContext();
originalContext.put(RequestContextConstants.AUTHORIZATION_HEADER, TEST_AUTH_HEADER);
originalContext.put("x-some-tenant-header", "v1");

assertEquals(originalContext, new RequestContext(originalContext));
}

@Test
void testCreateForTenantId() {
RequestContext requestContext = RequestContext.forTenantId(TENANT_ID);
Expand Down
Loading