Skip to content

Commit 500da59

Browse files
sichanyooSichan Yoo
andauthored
fix: Make HttpResponse.statusCode getter & setter thread-safe (#656)
* Use serial queue & hidden property to make getter & setter for HttpResponse.statusCode thread-safe. * Revert macOS client engine back to URLSession. --------- Co-authored-by: Sichan Yoo <[email protected]>
1 parent 129e98b commit 500da59

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

Sources/ClientRuntime/Networking/Http/HttpResponse.swift

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,37 @@
77

88
import protocol SmithyReadWrite.WireDataProviding
99
import AwsCommonRuntimeKit
10+
import class Foundation.DispatchQueue
1011

1112
public class HttpResponse: HttpUrlResponse, ResponseMessage {
1213

1314
public var headers: Headers
1415
public var body: ByteStream
15-
public var statusCode: HttpStatusCode
16+
17+
private var _statusCode: HttpStatusCode
18+
private let statusCodeQueue = DispatchQueue(label: "statusCodeSerialQueue")
19+
public var statusCode: HttpStatusCode {
20+
get {
21+
statusCodeQueue.sync {
22+
return _statusCode
23+
}
24+
}
25+
set {
26+
statusCodeQueue.sync {
27+
self._statusCode = newValue
28+
}
29+
}
30+
}
1631

1732
public init(headers: Headers = .init(), statusCode: HttpStatusCode = .processing, body: ByteStream = .noStream) {
1833
self.headers = headers
19-
self.statusCode = statusCode
34+
self._statusCode = statusCode
2035
self.body = body
2136
}
2237

2338
public init(headers: Headers = .init(), body: ByteStream, statusCode: HttpStatusCode) {
2439
self.body = body
25-
self.statusCode = statusCode
40+
self._statusCode = statusCode
2641
self.headers = headers
2742
}
2843
}

0 commit comments

Comments
 (0)