-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat!: Replace the XML encoder with a custom Smithy implementation (#619
- Loading branch information
Showing
109 changed files
with
2,220 additions
and
2,527 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
Sources/ClientRuntime/Networking/Http/Middlewares/RequestBody/BlobBodyMiddleware.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// | ||
// Copyright Amazon.com Inc. or its affiliates. | ||
// All Rights Reserved. | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
|
||
import struct Foundation.Data | ||
|
||
public struct BlobBodyMiddleware<OperationStackInput, | ||
OperationStackOutput: HttpResponseBinding>: Middleware { | ||
public let id: Swift.String = "BlobBodyMiddleware" | ||
|
||
let keyPath: KeyPath<OperationStackInput, Data?> | ||
|
||
public init(keyPath: KeyPath<OperationStackInput, Data?>) { | ||
self.keyPath = keyPath | ||
} | ||
|
||
public func handle<H>(context: Context, | ||
input: SerializeStepInput<OperationStackInput>, | ||
next: H) async throws -> OperationOutput<OperationStackOutput> | ||
where H: Handler, | ||
Self.MInput == H.Input, | ||
Self.MOutput == H.Output, | ||
Self.Context == H.Context { | ||
let body = HttpBody.data(input.operationInput[keyPath: keyPath]) | ||
input.builder.withBody(body) | ||
return try await next.handle(context: context, input: input) | ||
} | ||
|
||
public typealias MInput = SerializeStepInput<OperationStackInput> | ||
public typealias MOutput = OperationOutput<OperationStackOutput> | ||
public typealias Context = HttpContext | ||
} |
37 changes: 37 additions & 0 deletions
37
Sources/ClientRuntime/Networking/Http/Middlewares/RequestBody/BlobStreamBodyMiddleware.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// | ||
// Copyright Amazon.com Inc. or its affiliates. | ||
// All Rights Reserved. | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
|
||
import struct Foundation.Data | ||
|
||
public struct BlobStreamBodyMiddleware<OperationStackInput, | ||
OperationStackOutput: HttpResponseBinding>: Middleware { | ||
public let id: Swift.String = "BlobStreamBodyMiddleware" | ||
|
||
let keyPath: KeyPath<OperationStackInput, ByteStream?> | ||
|
||
public init(keyPath: KeyPath<OperationStackInput, ByteStream?>) { | ||
self.keyPath = keyPath | ||
} | ||
|
||
public func handle<H>(context: Context, | ||
input: SerializeStepInput<OperationStackInput>, | ||
next: H) async throws -> OperationOutput<OperationStackOutput> | ||
where H: Handler, | ||
Self.MInput == H.Input, | ||
Self.MOutput == H.Output, | ||
Self.Context == H.Context { | ||
if let byteStream = input.operationInput[keyPath: keyPath] { | ||
let body = HttpBody(byteStream: byteStream) | ||
input.builder.withBody(body) | ||
} | ||
return try await next.handle(context: context, input: input) | ||
} | ||
|
||
public typealias MInput = SerializeStepInput<OperationStackInput> | ||
public typealias MOutput = OperationOutput<OperationStackOutput> | ||
public typealias Context = HttpContext | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
Sources/ClientRuntime/Networking/Http/Middlewares/RequestBody/EnumBodyMiddleware.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// | ||
// Copyright Amazon.com Inc. or its affiliates. | ||
// All Rights Reserved. | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
|
||
import struct Foundation.Data | ||
|
||
public struct EnumBodyMiddleware<OperationStackInput, | ||
OperationStackOutput: HttpResponseBinding, | ||
Primitive: RawRepresentable>: Middleware where Primitive.RawValue == String { | ||
public let id: Swift.String = "EnumBodyMiddleware" | ||
|
||
let keyPath: KeyPath<OperationStackInput, Primitive?> | ||
|
||
public init(keyPath: KeyPath<OperationStackInput, Primitive?>) { | ||
self.keyPath = keyPath | ||
} | ||
|
||
public func handle<H>(context: Context, | ||
input: SerializeStepInput<OperationStackInput>, | ||
next: H) async throws -> OperationOutput<OperationStackOutput> | ||
where H: Handler, | ||
Self.MInput == H.Input, | ||
Self.MOutput == H.Output, | ||
Self.Context == H.Context { | ||
let bodyString = input.operationInput[keyPath: keyPath]?.rawValue ?? "" | ||
let body = HttpBody.data(Data(bodyString.utf8)) | ||
input.builder.withBody(body) | ||
return try await next.handle(context: context, input: input) | ||
} | ||
|
||
public typealias MInput = SerializeStepInput<OperationStackInput> | ||
public typealias MOutput = OperationOutput<OperationStackOutput> | ||
public typealias Context = HttpContext | ||
} |
60 changes: 60 additions & 0 deletions
60
...ces/ClientRuntime/Networking/Http/Middlewares/RequestBody/EventStreamBodyMiddleware.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
// | ||
// Copyright Amazon.com Inc. or its affiliates. | ||
// All Rights Reserved. | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
|
||
import struct Foundation.Data | ||
import typealias SmithyReadWrite.DocumentWritingClosure | ||
import typealias SmithyReadWrite.WritingClosure | ||
|
||
public struct EventStreamBodyMiddleware<OperationStackInput, | ||
OperationStackOutput: HttpResponseBinding, | ||
OperationStackInputPayload: MessageMarshallable>: | ||
Middleware { | ||
public let id: Swift.String = "EventStreamBodyMiddleware" | ||
|
||
let keyPath: KeyPath<OperationStackInput, AsyncThrowingStream<OperationStackInputPayload, Swift.Error>?> | ||
let defaultBody: String? | ||
|
||
public init( | ||
keyPath: KeyPath<OperationStackInput, AsyncThrowingStream<OperationStackInputPayload, Swift.Error>?>, | ||
defaultBody: String? = nil | ||
) { | ||
self.keyPath = keyPath | ||
self.defaultBody = defaultBody | ||
} | ||
|
||
public func handle<H>(context: Context, | ||
input: SerializeStepInput<OperationStackInput>, | ||
next: H) async throws -> OperationOutput<OperationStackOutput> | ||
where H: Handler, | ||
Self.MInput == H.Input, | ||
Self.MOutput == H.Output, | ||
Self.Context == H.Context { | ||
let encoder = context.getEncoder() | ||
if let eventStream = input.operationInput[keyPath: keyPath] { | ||
guard let messageEncoder = context.getMessageEncoder() else { | ||
fatalError("Message encoder is required for streaming payload") | ||
} | ||
guard let messageSigner = context.getMessageSigner() else { | ||
fatalError("Message signer is required for streaming payload") | ||
} | ||
let encoderStream = EventStream.DefaultMessageEncoderStream( | ||
stream: eventStream, | ||
messageEncoder: messageEncoder, | ||
requestEncoder: encoder, | ||
messageSigner: messageSigner | ||
) | ||
input.builder.withBody(.stream(encoderStream)) | ||
} else if let defaultBody { | ||
input.builder.withBody(HttpBody.data(Data(defaultBody.utf8))) | ||
} | ||
return try await next.handle(context: context, input: input) | ||
} | ||
|
||
public typealias MInput = SerializeStepInput<OperationStackInput> | ||
public typealias MOutput = OperationOutput<OperationStackOutput> | ||
public typealias Context = HttpContext | ||
} |
Oops, something went wrong.