Skip to content
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

fix: do not append to undefined/null header values #388

Merged
merged 2 commits into from Nov 4, 2019
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 12 additions & 0 deletions packages/util-user-agent-browser/src/index.spec.ts
Expand Up @@ -27,3 +27,15 @@ it("append to user agent", () => {
appendToUserAgent(request, "http/2.0");
expect(request.headers["X-Amz-User-Agent"]).toBe(`${defaultValue} http/2.0`);
});

it("append custom user agent when existing user agent was undefined", () => {
const request = {
headers: { "X-Amz-User-Agent": undefined as any },
method: "GET",
protocol: "json",
hostname: "foo.amazonaws.com",
path: "/"
};
appendToUserAgent(request, "http/2.0");
expect(request.headers["X-Amz-User-Agent"]).toBe("http/2.0");
});
6 changes: 5 additions & 1 deletion packages/util-user-agent-browser/src/index.ts
Expand Up @@ -15,5 +15,9 @@ export function appendToUserAgent(
request: HttpRequest,
userAgentPartial: string
): void {
request.headers["X-Amz-User-Agent"] += ` ${userAgentPartial}`;
if(request.headers["X-Amz-User-Agent"]) {
request.headers["X-Amz-User-Agent"] += ` ${userAgentPartial}`;
} else {
request.headers["X-Amz-User-Agent"] = userAgentPartial;
}
}