Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use serial queue & hidden property to make getter & setter for HttpRe…
Browse files Browse the repository at this point in the history
…sponse.statusCode thread-safe.
Sichan Yoo committed May 29, 2024
1 parent 129e98b commit e6b388b
Showing 2 changed files with 19 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -86,7 +86,7 @@ public extension DefaultSDKRuntimeConfiguration {
static func makeClient(
httpClientConfiguration: HttpClientConfiguration = defaultHttpClientConfiguration
) -> HTTPClient {
#if os(iOS) || os(tvOS) || os(watchOS) || os(visionOS) || os(macOS)
#if os(iOS) || os(tvOS) || os(watchOS) || os(visionOS) //|| os(macOS)

Check warning on line 89 in Sources/ClientRuntime/Config/DefaultSDKRuntimeConfiguration.swift

GitHub Actions / swiftlint

Prefer at least one space after slashes for comments (comment_spacing)

Check warning on line 89 in Sources/ClientRuntime/Config/DefaultSDKRuntimeConfiguration.swift

GitHub Actions / downstream (macos-13-xlarge, Xcode_14.1, platform=OS X)

unknown operating system for build configuration 'os'

Check warning on line 89 in Sources/ClientRuntime/Config/DefaultSDKRuntimeConfiguration.swift

GitHub Actions / downstream (macos-13-xlarge, Xcode_14.1, platform=tvOS Simulator,OS=16.1,name=Apple TV 4K (3rd ge...

unknown operating system for build configuration 'os'
return URLSessionHTTPClient(httpClientConfiguration: httpClientConfiguration)
#else
let connectTimeoutMs = httpClientConfiguration.connectTimeout.map { UInt32($0 * 1000) }
21 changes: 18 additions & 3 deletions Sources/ClientRuntime/Networking/Http/HttpResponse.swift
Original file line number Diff line number Diff line change
@@ -7,22 +7,37 @@

import protocol SmithyReadWrite.WireDataProviding
import AwsCommonRuntimeKit
import class Foundation.DispatchQueue

public class HttpResponse: HttpUrlResponse, ResponseMessage {

public var headers: Headers
public var body: ByteStream
public var statusCode: HttpStatusCode

private var _statusCode: HttpStatusCode
private let statusCodeQueue = DispatchQueue(label: "statusCodeSerialQueue")
public var statusCode: HttpStatusCode {
get {
statusCodeQueue.sync {
return _statusCode
}
}
set {
statusCodeQueue.sync {
self._statusCode = newValue
}
}
}

public init(headers: Headers = .init(), statusCode: HttpStatusCode = .processing, body: ByteStream = .noStream) {
self.headers = headers
self.statusCode = statusCode
self._statusCode = statusCode
self.body = body
}

public init(headers: Headers = .init(), body: ByteStream, statusCode: HttpStatusCode) {
self.body = body
self.statusCode = statusCode
self._statusCode = statusCode
self.headers = headers
}
}

0 comments on commit e6b388b

Please sign in to comment.