Skip to content

Commit

Permalink
Decode response header data from Codable userInfo (#565)
Browse files Browse the repository at this point in the history
* Rename HTTPBody to AWSHTTPBody

* Add AWSResponse to Codable userInfo

* Add decode functions for AWSResponse

* ResponseContainer for decoding

* Fix tests after userInfo changes

* Remove DictionaryDecoder

Now we pass the response via uesrInfo to the decoder and decode header, body and payload in the init(from) function, we can use the JSONDecoder for decoding responses.

* Fix tests

* Re-organise root element code

* Fix after merge

* Update Sources/SotoCore/Encoder/ResponseContainer.swift

Co-authored-by: Tim Condon <[email protected]>

---------

Co-authored-by: Tim Condon <[email protected]>
  • Loading branch information
adam-fowler and 0xTim authored Jul 18, 2023
1 parent f3d3461 commit 15744ff
Show file tree
Hide file tree
Showing 18 changed files with 278 additions and 2,310 deletions.
2 changes: 1 addition & 1 deletion Sources/SotoCore/AWSClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,7 @@ extension AWSClient {
url: URL,
httpMethod: HTTPMethod,
headers: HTTPHeaders = HTTPHeaders(),
body: HTTPBody,
body: AWSHTTPBody,
serviceConfig: AWSServiceConfig,
logger: Logger = AWSClient.loggingDisabled
) async throws -> HTTPHeaders {
Expand Down
2 changes: 1 addition & 1 deletion Sources/SotoCore/AWSService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ extension AWSService {
url: URL,
httpMethod: HTTPMethod,
headers: HTTPHeaders = HTTPHeaders(),
body: HTTPBody = .init(),
body: AWSHTTPBody = .init(),
logger: Logger = AWSClient.loggingDisabled
) async throws -> HTTPHeaders {
return try await self.client.signHeaders(url: url, httpMethod: httpMethod, headers: headers, body: body, serviceConfig: self.config, logger: logger)
Expand Down
2 changes: 1 addition & 1 deletion Sources/SotoCore/Concurrency/AnyAsyncSequence.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public struct AnyAsyncSequence<Element>: Sendable, AsyncSequence {

@usableFromInline var makeAsyncIteratorCallback: @Sendable () -> AsyncIteratorNextCallback

@inlinable init<SequenceOfBytes>(
@inlinable public init<SequenceOfBytes>(
_ asyncSequence: SequenceOfBytes
) where SequenceOfBytes: AsyncSequence & Sendable, SequenceOfBytes.Element == Element {
self.makeAsyncIteratorCallback = {
Expand Down
8 changes: 4 additions & 4 deletions Sources/SotoCore/Doc/AWSShape.swift
Original file line number Diff line number Diff line change
Expand Up @@ -141,15 +141,15 @@ public extension AWSEncodableShape {
guard value.base64count <= max else { throw Self.validationError("Length of \(parent).\(name) (\(value.base64count)) is greater than the maximum allowed value \(max).") }
}

func validate(_ value: HTTPBody, name: String, parent: String, min: Int) throws {
func validate(_ value: AWSHTTPBody, name: String, parent: String, min: Int) throws {
if let size = value.length {
guard size >= min else {
throw Self.validationError("Length of \(parent).\(name) (\(size)) is less than minimum allowed value \(min).")
}
}
}

func validate(_ value: HTTPBody, name: String, parent: String, max: Int) throws {
func validate(_ value: AWSHTTPBody, name: String, parent: String, max: Int) throws {
if let size = value.length {
guard size <= max else {
throw Self.validationError("Length of \(parent).\(name) (\(size)) is greater than the maximum allowed value \(max).")
Expand Down Expand Up @@ -205,12 +205,12 @@ public extension AWSEncodableShape {
try validate(value, name: name, parent: parent, max: max)
}

func validate(_ value: HTTPBody?, name: String, parent: String, min: Int) throws {
func validate(_ value: AWSHTTPBody?, name: String, parent: String, min: Int) throws {
guard let value = value else { return }
try validate(value, name: name, parent: parent, min: min)
}

func validate(_ value: HTTPBody?, name: String, parent: String, max: Int) throws {
func validate(_ value: AWSHTTPBody?, name: String, parent: String, max: Int) throws {
guard let value = value else { return }
try validate(value, name: name, parent: parent, max: max)
}
Expand Down
Loading

0 comments on commit 15744ff

Please sign in to comment.