Skip to content

Commit

Permalink
fix: guard against null projectId in Firestore routing header
Browse files Browse the repository at this point in the history
Fixes: #2205.
  • Loading branch information
meltsufin committed Sep 29, 2023
1 parent 1e8602d commit 29229f7
Showing 1 changed file with 7 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -166,11 +166,13 @@ public FirestoreTemplate firestoreTemplate(
public ClientInterceptor firestoreRoutingHeadersInterceptor() {
// add routing header for custom database id
Metadata routingHeader = new Metadata();
Metadata.Key<String> key =
Metadata.Key.of(Headers.DYNAMIC_ROUTING_HEADER_KEY, Metadata.ASCII_STRING_MARSHALLER);
routingHeader.put(key,
"project_id=" + PERCENT_ESCAPER.escape(projectId)
+ "&database_id=" + PERCENT_ESCAPER.escape(databaseId));
if (projectId != null && databaseId != null) {
Metadata.Key<String> key =
Metadata.Key.of(Headers.DYNAMIC_ROUTING_HEADER_KEY, Metadata.ASCII_STRING_MARSHALLER);
routingHeader.put(key,
"project_id=" + PERCENT_ESCAPER.escape(projectId)
+ "&database_id=" + PERCENT_ESCAPER.escape(databaseId));
}
return MetadataUtils.newAttachHeadersInterceptor(routingHeader);
}

Expand Down

0 comments on commit 29229f7

Please sign in to comment.