diff --git a/Sources/SmithyHTTPAPI/Headers.swift b/Sources/SmithyHTTPAPI/Headers.swift index eef01d9b8..6358ecc6f 100644 --- a/Sources/SmithyHTTPAPI/Headers.swift +++ b/Sources/SmithyHTTPAPI/Headers.swift @@ -138,15 +138,7 @@ public struct Headers: Sendable { } public func exists(name: String) -> Bool { - guard headers.index(of: name) != nil else { - return false - } - - guard let value = value(for: name) else { - return false - } - - return !value.isEmpty + headers.index(of: name) != nil } /// The dictionary representation of all headers. diff --git a/Tests/ClientRuntimeTests/NetworkingTests/Http/HttpHeadersTests.swift b/Tests/SmithyHTTPAPITests/HeadersTests.swift similarity index 87% rename from Tests/ClientRuntimeTests/NetworkingTests/Http/HttpHeadersTests.swift rename to Tests/SmithyHTTPAPITests/HeadersTests.swift index 45acd0ccd..dde63ba32 100644 --- a/Tests/ClientRuntimeTests/NetworkingTests/Http/HttpHeadersTests.swift +++ b/Tests/SmithyHTTPAPITests/HeadersTests.swift @@ -1,13 +1,14 @@ -/* - * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * SPDX-License-Identifier: Apache-2.0. - */ +// +// Copyright Amazon.com Inc. or its affiliates. +// All Rights Reserved. +// +// SPDX-License-Identifier: Apache-2.0 +// import SmithyHTTPAPI import XCTest -import ClientRuntime -class HttpHeadersTests: XCTestCase { +class HeadersTests: XCTestCase { var headersAsDictionaryWithArray = [String: [String]]() var headersAsDictionary = [String: String]() @@ -123,4 +124,21 @@ class HttpHeadersTests: XCTestCase { XCTAssertEqual(headerA, headerB) XCTAssertEqual(headerA.hashValue, headerB.hashValue) } + + // MARK: - exists() + + func test_exists_trueIfHeaderExists() { + let subject = Headers(["a": "abc"]) + XCTAssertTrue(subject.exists(name: "a")) + } + + func test_exists_falseIfHeaderDoesntExist() { + let subject = Headers(["a": "abc"]) + XCTAssertFalse(subject.exists(name: "b")) + } + + func test_exists_trueIfHeaderValueIsEmptyString() { + let subject = Headers(["a": ""]) + XCTAssertTrue(subject.exists(name: "a")) + } }