Skip to content

Commit

Permalink
refactor: add copy constructor to request context (#65)
Browse files Browse the repository at this point in the history
  • Loading branch information
aaron-steinfeld authored Nov 18, 2024
1 parent d818b0d commit bc147b5
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
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

0 comments on commit bc147b5

Please sign in to comment.