-
Notifications
You must be signed in to change notification settings - Fork 125
notify delegate about connect errors #245
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 3 commits
910a109
e2b46a2
1687c89
0b86e7d
1c123a2
c282a93
49f742b
8e27e62
747b8a9
0970f30
ef6695e
b030743
7696be3
ffeb515
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2005,4 +2005,38 @@ class HTTPClientTests: XCTestCase { | |
|
||
self.defaultClient = nil // so it doesn't get shut down again. | ||
} | ||
|
||
func testConnectErrorPropagatedToDelegate() throws { | ||
class TestDelegate: HTTPClientResponseDelegate { | ||
typealias Response = Void | ||
var error: Error? | ||
func didFinishRequest(task: HTTPClient.Task<Void>) throws {} | ||
func didReceiveError(task: HTTPClient.Task<Response>, _ error: Error) { | ||
self.error = error | ||
} | ||
} | ||
|
||
let httpBin = HTTPBin() | ||
let httpClient = HTTPClient(eventLoopGroupProvider: .shared(self.clientGroup)) | ||
defer { | ||
XCTAssertNoThrow(try httpClient.syncShutdown()) | ||
} | ||
|
||
let delegate = TestDelegate() | ||
let request = try HTTPClient.Request(url: "http://localhost:\(httpBin.port)/get") | ||
do { | ||
try httpBin.shutdown() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this should be in an |
||
_ = try httpClient.execute(request: request, delegate: delegate).wait() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please use
we literally had security issues before because of this pattern. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done, thank you for catching this! |
||
XCTFail("Should fail") | ||
} catch { | ||
switch (error, delegate.error) { | ||
case (_ as NIOConnectionError, _ as NIOConnectionError): | ||
break | ||
case (_ as NIOConnectionError, .none): | ||
XCTFail("Delegate error is not \(error)") | ||
default: | ||
XCTFail("Unexpected error: \(error)") | ||
} | ||
} | ||
} | ||
} |
Uh oh!
There was an error while loading. Please reload this page.