Skip to content

Commit

Permalink
feat!: Renamed several HTTP-related types (#1638)
Browse files Browse the repository at this point in the history
  • Loading branch information
jbelkins authored Jul 17, 2024
1 parent bce9336 commit 00396a7
Show file tree
Hide file tree
Showing 35 changed files with 106 additions and 101 deletions.
1 change: 1 addition & 0 deletions .swiftlint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ disabled_rules:
- operator_whitespace
- large_tuple
- trailing_comma
- non_optional_string_data_conversion

opt_in_rules:
- empty_count
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class MockHttpClientEngine: HTTPClient {
// Public initializer
public init() {}

func successHttpResponse(request: SdkHttpRequest) -> HttpResponse {
func successHttpResponse(request: SmithyHTTPAPI.HTTPRequest) -> HTTPResponse {
let errorResponsePayload = """
<Error>
<Code>SlowDown</Code>
Expand All @@ -30,14 +30,14 @@ public class MockHttpClientEngine: HTTPClient {
</Error>
"""
request.withHeader(name: "Date", value: "Wed, 21 Oct 2015 07:28:00 GMT")
return HttpResponse(
return HTTPResponse(
headers: request.headers,
body: ByteStream.data(errorResponsePayload.data(using: .utf8)),
statusCode: HttpStatusCode.ok
statusCode: .ok
)
}

public func send(request: SdkHttpRequest) async throws -> HttpResponse {
public func send(request: SmithyHTTPAPI.HTTPRequest) async throws -> HTTPResponse {
return successHttpResponse(request: request)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@

import class Smithy.Context
import struct SmithyHTTPAPI.Endpoint
import class SmithyHTTPAPI.SdkHttpRequest
import class SmithyHTTPAPI.SdkHttpRequestBuilder
import class SmithyHTTPAPI.HTTPRequest
import class SmithyHTTPAPI.HTTPRequestBuilder
import struct SmithyHTTPAuthAPI.SelectedAuthScheme
import enum SmithyHTTPAuthAPI.SigningAlgorithm
import enum SmithyHTTPAuthAPI.SigningPropertyKeys
Expand All @@ -22,7 +22,7 @@ import protocol ClientRuntime.Middleware
import struct ClientRuntime.OperationOutput

public struct EndpointResolverMiddleware<OperationStackOutput, Params: EndpointsRequestContextProviding>: Middleware {
public typealias MInput = SmithyHTTPAPI.SdkHttpRequestBuilder
public typealias MInput = HTTPRequestBuilder
public typealias MOutput = ClientRuntime.OperationOutput<OperationStackOutput>

public let id: Swift.String = "EndpointResolverMiddleware"
Expand All @@ -45,7 +45,7 @@ public struct EndpointResolverMiddleware<OperationStackOutput, Params: Endpoints

public func handle<H>(
context: Smithy.Context,
input: SmithyHTTPAPI.SdkHttpRequestBuilder,
input: HTTPRequestBuilder,
next: H
) async throws -> ClientRuntime.OperationOutput<OperationStackOutput>
where H: Handler,
Expand All @@ -62,10 +62,10 @@ public struct EndpointResolverMiddleware<OperationStackOutput, Params: Endpoints
extension EndpointResolverMiddleware: ApplyEndpoint {

public func apply(
request: SdkHttpRequest,
request: HTTPRequest,
selectedAuthScheme: SelectedAuthScheme?,
attributes: Smithy.Context
) async throws -> SdkHttpRequest {
) async throws -> HTTPRequest {
let builder = request.toBuilder()

let endpoint = try endpointResolverBlock(endpointParams)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// SPDX-License-Identifier: Apache-2.0
//

import class SmithyHTTPAPI.HttpResponse
import class SmithyHTTPAPI.HTTPResponse
import protocol ClientRuntime.HTTPError

/// An error that may be returned by AWS when the access key used cannot be found by the server.
Expand All @@ -14,12 +14,12 @@ import protocol ClientRuntime.HTTPError
public struct InvalidAccessKeyId: AWSServiceError, HTTPError, Error {

static var errorCode: String { "InvalidAccessKeyId" }
public var httpResponse: HttpResponse
public var httpResponse: HTTPResponse
public var requestID: String?
public var requestID2: String?
public var message: String?

init(httpResponse: HttpResponse, message: String?, requestID: String?, requestID2: String?) {
init(httpResponse: HTTPResponse, message: String?, requestID: String?, requestID2: String?) {
self.httpResponse = httpResponse
self.message = message
self.requestID = requestID
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// SPDX-License-Identifier: Apache-2.0
//

import class SmithyHTTPAPI.HttpResponse
import class SmithyHTTPAPI.HTTPResponse
import protocol ClientRuntime.ServiceError
import protocol ClientRuntime.HTTPError

Expand All @@ -21,7 +21,7 @@ protocol UnknownAWSHTTPErrorCandidate: ServiceError, HTTPError, Error {
/// If a HTTP response matches this error type, then an instance of this error should be created.
static var errorCode: String { get }

init(httpResponse: HttpResponse, message: String?, requestID: String?, requestID2: String?)
init(httpResponse: HTTPResponse, message: String?, requestID: String?, requestID2: String?)
}

// These extensions provide for conformance with the `ServiceError` and
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* SPDX-License-Identifier: Apache-2.0.
*/

import class SmithyHTTPAPI.HttpResponse
import class SmithyHTTPAPI.HTTPResponse
import ClientRuntime

/// AWS specific Service Error structure used when exact error could not be deduced from the `HttpResponse`
Expand All @@ -21,7 +21,7 @@ import ClientRuntime

public var requestID2: String?

public var httpResponse: HttpResponse
public var httpResponse: HTTPResponse
}

extension UnknownAWSHTTPServiceError {
Expand All @@ -34,15 +34,15 @@ extension UnknownAWSHTTPServiceError {
/// - requestID2: The request ID2 associated with this error (defined on S3 only.) Defaults to `nil`.
/// - typeName: The non-namespaced name of the error type for this error.
public init(
httpResponse: HttpResponse,
httpResponse: HTTPResponse,
message: String?,
requestID: String?,
requestID2: String? = nil,
typeName: String?
) {
self.typeName = typeName
self.message = message
self.requestID = requestID ?? httpResponse.requestId
self.requestID = requestID ?? httpResponse.requestID
self.requestID2 = requestID2
self.httpResponse = httpResponse
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,18 @@
* SPDX-License-Identifier: Apache-2.0.
*/

import class SmithyHTTPAPI.HttpResponse
import class SmithyHTTPAPI.HTTPResponse
import ClientRuntime

public extension HttpResponse {
public extension HTTPResponse {

/// The value of the x-amz-request-id header.
var requestId: String? {
var requestID: String? {
return headers.value(for: "x-amz-request-id")
}

/// The value of the x-amz-id-2 header.
var requestId2: String? {
var requestID2: String? {
return headers.value(for: "x-amz-id-2")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ import SmithyHTTPAPI

public struct AWSS3ErrorWith200StatusXMLMiddleware<OperationStackInput, OperationStackOutput>: Middleware {
public let id: String = "AWSS3ErrorWith200StatusXMLMiddleware"
private let errorStatusCode: HttpStatusCode = .internalServerError
private let errorStatusCode: HTTPStatusCode = .internalServerError

public init() {}

public func handle<H>(context: Context,
input: SdkHttpRequest,
input: HTTPRequest,
next: H) async throws -> OperationOutput<OperationStackOutput>
where H: Handler,
Self.MInput == H.Input,
Expand All @@ -35,7 +35,7 @@ public struct AWSS3ErrorWith200StatusXMLMiddleware<OperationStackInput, Operatio
return response
}

private func isErrorWith200Status(response: HttpResponse) async throws -> Bool {
private func isErrorWith200Status(response: HTTPResponse) async throws -> Bool {
// Check if the status code is OK (200)
guard response.statusCode == .ok else {
return false
Expand All @@ -51,7 +51,7 @@ public struct AWSS3ErrorWith200StatusXMLMiddleware<OperationStackInput, Operatio
return xmlString.contains("<Error>")
}

public typealias MInput = SdkHttpRequest
public typealias MInput = HTTPRequest
public typealias MOutput = OperationOutput<OperationStackOutput>
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public struct FlexibleChecksumsRequestMiddleware<OperationStackInput, OperationS
return try await next.handle(context: context, input: input)
}

private func addHeaders(builder: SdkHttpRequestBuilder, attributes: Context) async throws {
private func addHeaders(builder: HTTPRequestBuilder, attributes: Context) async throws {
if case(.stream(let stream)) = builder.body {
attributes.isChunkedEligibleStream = stream.isEligibleForChunkedStreaming
if stream.isEligibleForChunkedStreaming {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public struct FlexibleChecksumsResponseMiddleware<OperationStackInput, Operation
}

public func handle<H>(context: Context,
input: SdkHttpRequest,
input: HTTPRequest,
next: H) async throws -> OperationOutput<OperationStackOutput>
where H: Handler,
Self.MInput == H.Input,
Expand All @@ -50,7 +50,7 @@ public struct FlexibleChecksumsResponseMiddleware<OperationStackInput, Operation
return output
}

private func validateChecksum(response: HttpResponse, logger: any LogAgent, attributes: Context) async throws {
private func validateChecksum(response: HTTPResponse, logger: any LogAgent, attributes: Context) async throws {
// Exit if validation should not be performed
if !validationMode {
logger.info("Checksum validation should not be performed! Skipping workflow...")
Expand Down Expand Up @@ -112,7 +112,7 @@ public struct FlexibleChecksumsResponseMiddleware<OperationStackInput, Operation
}
}

public typealias MInput = SdkHttpRequest
public typealias MInput = HTTPRequest
public typealias MOutput = OperationOutput<OperationStackOutput>
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,11 @@ public struct Sha256TreeHashMiddleware<OperationStackInput, OperationStackOutput
return try await next.handle(context: context, input: input)
}

private func addHashes(request: SdkHttpRequest, builder: SdkHttpRequestBuilder, context: Context) async throws {
private func addHashes(
request: SmithyHTTPAPI.HTTPRequest,
builder: HTTPRequestBuilder,
context: Context
) async throws {
switch request.body {
case .data(let data):
guard let data = data else {
Expand Down Expand Up @@ -104,7 +108,7 @@ public struct Sha256TreeHashMiddleware<OperationStackInput, OperationStackOutput
return data.encodeToHexString()
}

public typealias MInput = SdkHttpRequestBuilder
public typealias MInput = HTTPRequestBuilder
public typealias MOutput = OperationOutput<OperationStackOutput>
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public struct UserAgentMiddleware<OperationStackInput, OperationStackOutput>: Mi
}

public func handle<H>(context: Context,
input: SdkHttpRequestBuilder,
input: HTTPRequestBuilder,
next: H) async throws -> OperationOutput<OperationStackOutput>
where H: Handler,
Self.MInput == H.Input,
Expand All @@ -31,19 +31,19 @@ public struct UserAgentMiddleware<OperationStackInput, OperationStackOutput>: Mi
return try await next.handle(context: context, input: input)
}

private func addHeader(builder: SdkHttpRequestBuilder) {
private func addHeader(builder: HTTPRequestBuilder) {
builder.withHeader(name: USER_AGENT, value: metadata.userAgent)
}

public typealias MInput = SdkHttpRequestBuilder
public typealias MInput = HTTPRequestBuilder
public typealias MOutput = OperationOutput<OperationStackOutput>
}

extension UserAgentMiddleware: HttpInterceptor {
public typealias InputType = OperationStackInput
public typealias OutputType = OperationStackOutput

public func modifyBeforeRetryLoop(context: some MutableRequest<Self.InputType, SdkHttpRequest>) async throws {
public func modifyBeforeRetryLoop(context: some MutableRequest<Self.InputType, HTTPRequest>) async throws {
let builder = context.getRequest().toBuilder()
addHeader(builder: builder)
context.updateRequest(updated: builder.build())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public struct XAmzTargetMiddleware<OperationStackInput, OperationStackOutput>: M
return try await next.handle(context: context, input: input)
}

private func addHeader(builder: SdkHttpRequestBuilder) {
private func addHeader(builder: HTTPRequestBuilder) {
builder.withHeader(name: "X-Amz-Target", value: xAmzTarget)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import protocol ClientRuntime.BaseError
import enum ClientRuntime.BaseErrorDecodeError
import class SmithyHTTPAPI.HttpResponse
import class SmithyHTTPAPI.HTTPResponse
import class SmithyJSON.Reader

public struct AWSJSONError: BaseError {
Expand All @@ -16,10 +16,10 @@ public struct AWSJSONError: BaseError {
public let requestID: String?
public var errorBodyReader: Reader { responseReader }

public let httpResponse: HttpResponse
public let httpResponse: HTTPResponse
private let responseReader: Reader

public init(httpResponse: HttpResponse, responseReader: Reader, noErrorWrapping: Bool) throws {
public init(httpResponse: HTTPResponse, responseReader: Reader, noErrorWrapping: Bool) throws {
let code: String? = try httpResponse.headers.value(for: "X-Amzn-Errortype")
?? responseReader["code"].readIfPresent()
?? responseReader["__type"].readIfPresent()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,18 @@

import protocol ClientRuntime.BaseError
import enum ClientRuntime.BaseErrorDecodeError
import class SmithyHTTPAPI.HttpResponse
import class SmithyHTTPAPI.HTTPResponse
import class SmithyXML.Reader

public struct AWSQueryError: BaseError {
public let code: String
public let message: String?
public let requestID: String?
public let httpResponse: HttpResponse
public let httpResponse: HTTPResponse
public let responseReader: Reader
public let errorBodyReader: Reader

public init(httpResponse: HttpResponse, responseReader: Reader, noErrorWrapping: Bool) throws {
public init(httpResponse: HTTPResponse, responseReader: Reader, noErrorWrapping: Bool) throws {
self.errorBodyReader = noErrorWrapping ? responseReader : responseReader["Error"]
let code: String? = try errorBodyReader["Code"].readIfPresent()
let message: String? = try errorBodyReader["Message"].readIfPresent()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import protocol ClientRuntime.BaseError
import enum ClientRuntime.BaseErrorDecodeError
import class SmithyHTTPAPI.HttpResponse
import class SmithyHTTPAPI.HTTPResponse
import class SmithyXML.Reader

public struct EC2QueryError: BaseError {
Expand All @@ -16,10 +16,10 @@ public struct EC2QueryError: BaseError {
public let requestID: String?
public let errorBodyReader: Reader

public let httpResponse: HttpResponse
public let httpResponse: HTTPResponse
public let responseReader: Reader

public init(httpResponse: HttpResponse, responseReader: Reader, noErrorWrapping: Bool) throws {
public init(httpResponse: HTTPResponse, responseReader: Reader, noErrorWrapping: Bool) throws {
self.httpResponse = httpResponse
self.responseReader = responseReader
self.errorBodyReader = responseReader["Errors"]["Error"]
Expand Down
Loading

0 comments on commit 00396a7

Please sign in to comment.