-
Notifications
You must be signed in to change notification settings - Fork 30
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: Consider an empty string header value to be present #832
Conversation
} | ||
|
||
return !value.isEmpty | ||
headers.index(of: name) != nil |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The previous definition of exists
was wrong because it considered a header with an empty string for its value to "not exist". Turns out a header with empty string value is valid, so it should definitely "exist".
I suspect that the reason for this logic is that the previous developers changed the definition of "exists" to suit the behavior demanded by empty-header protocol tests, which is wrong and is being fixed by Smithy team.
Package.swift
Outdated
.testTarget( | ||
name: "SmithyHTTPAPITests", | ||
dependencies: ["SmithyHTTPAPI"] | ||
), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added a new test target & moved the Headers
tests into it, since Headers
is in the SmithyHTTPAPI
module.
func test_exists_trueIfHeaderValueIsEmptyString() { | ||
let subject = Headers(["a": ""]) | ||
XCTAssertTrue(subject.exists(name: "a")) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These new tests check the expected behavior for the exists()
method on Headers
.
This PR is failing the downstream CI builds because the This PR should merge when this PR ships in a new version of Smithy: |
Closing this PR because this change is being made in #843 (update to Smithy 1.52) instead. |
Issue #
Description of changes
An empty string is an acceptable value for a HTTP header, and SDKs should send an empty string value for a header when one is passed.
Swift implements this behavior correctly, but incorrectly validates "forbidden headers" in a protocol test by considering a HTTP header to "not exist" when its value is an empty string.
This PR fixes the
exists()
method on theHeaders
type so that it returnstrue
rather thanfalse
when the header being checked has an empty string as its value.Note that the current
NullAndEmptyHeaders
protocol tests (in RestJSON & RestXML) for this behavior are incorrect, and this PR will cause the current version of these tests to fail. These tests are being corrected in a future version of Smithy and this PR should be merged only when that Smithy version is adopted.Also:
SmithyHTTPAPITests
test target and move theHeaders
tests into it fromClientRuntimeTests
.Scope
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.