Skip to content

Commit

Permalink
Merge pull request #962 from murgatroid99/incoming_metadata_forgiving
Browse files Browse the repository at this point in the history
Warn instead of failing when constructing metadata from remote end
  • Loading branch information
murgatroid99 authored Jul 11, 2019
2 parents ad378d3 + 5b87ceb commit a456547
Showing 1 changed file with 23 additions and 18 deletions.
41 changes: 23 additions & 18 deletions packages/grpc-js/src/metadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ function validate(key: string, value?: MetadataValue): void {
}
}

interface MetadataOptions {
export interface MetadataOptions {
/* Signal that the request is idempotent. Defaults to false */
idempotentRequest?: boolean;
/* Signal that the call should not return UNAVAILABLE before it has
Expand Down Expand Up @@ -240,24 +240,29 @@ export class Metadata {

const values = headers[key];

if (isBinaryKey(key)) {
if (Array.isArray(values)) {
values.forEach(value => {
result.add(key, Buffer.from(value, 'base64'));
});
} else if (values !== undefined) {
values.split(',').forEach(v => {
result.add(key, Buffer.from(v.trim(), 'base64'));
});
}
} else {
if (Array.isArray(values)) {
values.forEach(value => {
result.add(key, value);
});
} else if (values !== undefined) {
values.split(',').forEach(v => result.add(key, v.trim()));
try {
if (isBinaryKey(key)) {
if (Array.isArray(values)) {
values.forEach(value => {
result.add(key, Buffer.from(value, 'base64'));
});
} else if (values !== undefined) {
values.split(',').forEach(v => {
result.add(key, Buffer.from(v.trim(), 'base64'));
});
}
} else {
if (Array.isArray(values)) {
values.forEach(value => {
result.add(key, value);
});
} else if (values !== undefined) {
values.split(',').forEach(v => result.add(key, v.trim()));
}
}
} catch (error) {
error.message = `Failed to add metadata entry ${key}: ${values}. ${error.message}`;
process.emitWarning(error);
}
});
return result;
Expand Down

0 comments on commit a456547

Please sign in to comment.