mirror of
https://github.com/apple/swift-nio
synced 2026-11-27 05:04:22 +00:00
ChannelPipeline: addHandler and removeHandler instead of add/remove (#817)
Motivation: - `ChannelPipeline.add(name:handler:...)` had a strange order of arguments - `remove(handler:)` and `remove(ctx:)` both remove `ChannelHandler`s but they read like they remove different things So let's just fix the argument order and name them `addHandler` and `removeHandler` making clear what they do. Modifications: - rename all `ChannelPipeline.add(name:handler:...)`s to `ChannelPipeline.addHandler(_:name:...)` - rename all `ChannelPipeline.remove(...)`s to `ChannelPipeline.removeHandler(...)` Result: more readable and consistent code
This commit is contained in:
1 parent
5d27e59bd9
commit
46ffd630de
50 files changed
+539
-425
No files matched your search
@@ -125,11 +125,11 @@ class HTTPDecoderLengthTest: XCTestCase {
|
||||
}
|
||||
}
|
||||
|
||||
XCTAssertNoThrow(try channel.pipeline.add(handler: HTTPRequestEncoder()).wait())
|
||||
XCTAssertNoThrow(try channel.pipeline.add(handler: HTTPResponseDecoder()).wait())
|
||||
XCTAssertNoThrow(try channel.pipeline.addHandler(HTTPRequestEncoder()).wait())
|
||||
XCTAssertNoThrow(try channel.pipeline.addHandler(HTTPResponseDecoder()).wait())
|
||||
|
||||
let handler = ChannelInactiveHandler(eofMechanism)
|
||||
XCTAssertNoThrow(try channel.pipeline.add(handler: handler).wait())
|
||||
XCTAssertNoThrow(try channel.pipeline.addHandler(handler).wait())
|
||||
|
||||
// Prime the decoder with a GET and consume it.
|
||||
XCTAssertTrue(try channel.writeOutbound(HTTPClientRequestPart.head(HTTPRequestHead(version: version, method: .GET, uri: "/"))))
|
||||
@@ -188,11 +188,11 @@ class HTTPDecoderLengthTest: XCTestCase {
|
||||
private func assertIgnoresLengthFields(requestMethod: HTTPMethod,
|
||||
responseStatus: HTTPResponseStatus,
|
||||
responseFramingField: FramingField) throws {
|
||||
XCTAssertNoThrow(try channel.pipeline.add(handler: HTTPRequestEncoder()).wait())
|
||||
XCTAssertNoThrow(try channel.pipeline.add(handler: HTTPResponseDecoder()).wait())
|
||||
XCTAssertNoThrow(try channel.pipeline.addHandler(HTTPRequestEncoder()).wait())
|
||||
XCTAssertNoThrow(try channel.pipeline.addHandler(HTTPResponseDecoder()).wait())
|
||||
|
||||
let handler = MessageEndHandler<HTTPResponseHead, ByteBuffer>()
|
||||
XCTAssertNoThrow(try channel.pipeline.add(handler: handler).wait())
|
||||
XCTAssertNoThrow(try channel.pipeline.addHandler(handler).wait())
|
||||
|
||||
// Prime the decoder with a request and consume it.
|
||||
XCTAssertTrue(try channel.writeOutbound(HTTPClientRequestPart.head(HTTPRequestHead(version: .init(major: 1, minor: 1),
|
||||
@@ -292,10 +292,10 @@ class HTTPDecoderLengthTest: XCTestCase {
|
||||
}
|
||||
|
||||
private func assertRequestTransferEncodingHasNoBody(transferEncodingHeader: String) throws {
|
||||
XCTAssertNoThrow(try channel.pipeline.add(handler: HTTPRequestDecoder()).wait())
|
||||
XCTAssertNoThrow(try channel.pipeline.addHandler(HTTPRequestDecoder()).wait())
|
||||
|
||||
let handler = MessageEndHandler<HTTPRequestHead, ByteBuffer>()
|
||||
XCTAssertNoThrow(try channel.pipeline.add(handler: handler).wait())
|
||||
XCTAssertNoThrow(try channel.pipeline.addHandler(handler).wait())
|
||||
|
||||
// Send a GET with the appropriate Transfer Encoding header.
|
||||
XCTAssertNoThrow(try channel.writeInbound(ByteBuffer(string: "POST / HTTP/1.1\r\nTransfer-Encoding: \(transferEncodingHeader)\r\n\r\n")))
|
||||
@@ -327,11 +327,11 @@ class HTTPDecoderLengthTest: XCTestCase {
|
||||
}
|
||||
|
||||
private func assertResponseTransferEncodingHasBodyTerminatedByEOF(transferEncodingHeader: String, eofMechanism: EOFMechanism) throws {
|
||||
XCTAssertNoThrow(try channel.pipeline.add(handler: HTTPRequestEncoder()).wait())
|
||||
XCTAssertNoThrow(try channel.pipeline.add(handler: HTTPResponseDecoder()).wait())
|
||||
XCTAssertNoThrow(try channel.pipeline.addHandler(HTTPRequestEncoder()).wait())
|
||||
XCTAssertNoThrow(try channel.pipeline.addHandler(HTTPResponseDecoder()).wait())
|
||||
|
||||
let handler = MessageEndHandler<HTTPResponseHead, ByteBuffer>()
|
||||
XCTAssertNoThrow(try channel.pipeline.add(handler: handler).wait())
|
||||
XCTAssertNoThrow(try channel.pipeline.addHandler(handler).wait())
|
||||
|
||||
// Prime the decoder with a request and consume it.
|
||||
XCTAssertTrue(try channel.writeOutbound(HTTPClientRequestPart.head(HTTPRequestHead(version: .init(major: 1, minor: 1),
|
||||
@@ -398,7 +398,7 @@ class HTTPDecoderLengthTest: XCTestCase {
|
||||
}
|
||||
|
||||
func testRequestWithTEAndContentLengthErrors() throws {
|
||||
XCTAssertNoThrow(try channel.pipeline.add(handler: HTTPRequestDecoder()).wait())
|
||||
XCTAssertNoThrow(try channel.pipeline.addHandler(HTTPRequestDecoder()).wait())
|
||||
|
||||
// Send a GET with the invalid headers.
|
||||
do {
|
||||
@@ -416,8 +416,8 @@ class HTTPDecoderLengthTest: XCTestCase {
|
||||
}
|
||||
|
||||
func testResponseWithTEAndContentLengthErrors() throws {
|
||||
XCTAssertNoThrow(try channel.pipeline.add(handler: HTTPRequestEncoder()).wait())
|
||||
XCTAssertNoThrow(try channel.pipeline.add(handler: HTTPResponseDecoder()).wait())
|
||||
XCTAssertNoThrow(try channel.pipeline.addHandler(HTTPRequestEncoder()).wait())
|
||||
XCTAssertNoThrow(try channel.pipeline.addHandler(HTTPResponseDecoder()).wait())
|
||||
|
||||
// Prime the decoder with a request.
|
||||
XCTAssertTrue(try channel.writeOutbound(HTTPClientRequestPart.head(HTTPRequestHead(version: .init(major: 1, minor: 1),
|
||||
@@ -440,7 +440,7 @@ class HTTPDecoderLengthTest: XCTestCase {
|
||||
}
|
||||
|
||||
private func assertRequestWithInvalidCLErrors(contentLengthField: String) throws {
|
||||
XCTAssertNoThrow(try channel.pipeline.add(handler: HTTPRequestDecoder()).wait())
|
||||
XCTAssertNoThrow(try channel.pipeline.addHandler(HTTPRequestDecoder()).wait())
|
||||
|
||||
// Send a GET with the invalid headers.
|
||||
do {
|
||||
@@ -474,7 +474,7 @@ class HTTPDecoderLengthTest: XCTestCase {
|
||||
func testRequestWithIdenticalContentLengthRepeatedErrors() throws {
|
||||
// This is another case where http_parser is, if not wrong, then aggressively interpreting
|
||||
// the spec. Regardless, we match it.
|
||||
XCTAssertNoThrow(try channel.pipeline.add(handler: HTTPRequestDecoder()).wait())
|
||||
XCTAssertNoThrow(try channel.pipeline.addHandler(HTTPRequestDecoder()).wait())
|
||||
|
||||
// Send two POSTs with repeated content length, one with one field and one with two.
|
||||
// Both should error.
|
||||
@@ -495,7 +495,7 @@ class HTTPDecoderLengthTest: XCTestCase {
|
||||
func testRequestWithMultipleIdenticalContentLengthFieldsErrors() throws {
|
||||
// This is another case where http_parser is, if not wrong, then aggressively interpreting
|
||||
// the spec. Regardless, we match it.
|
||||
XCTAssertNoThrow(try channel.pipeline.add(handler: HTTPRequestDecoder()).wait())
|
||||
XCTAssertNoThrow(try channel.pipeline.addHandler(HTTPRequestDecoder()).wait())
|
||||
|
||||
do {
|
||||
try channel.writeInbound(ByteBuffer(string: "POST / HTTP/1.1\r\nContent-Length: 4\r\nContent-Length: 4\r\n\r\n"))
|
||||
@@ -512,10 +512,10 @@ class HTTPDecoderLengthTest: XCTestCase {
|
||||
}
|
||||
|
||||
func testRequestWithoutExplicitLengthIsZeroLength() throws {
|
||||
XCTAssertNoThrow(try channel.pipeline.add(handler: HTTPRequestDecoder()).wait())
|
||||
XCTAssertNoThrow(try channel.pipeline.addHandler(HTTPRequestDecoder()).wait())
|
||||
|
||||
let handler = MessageEndHandler<HTTPRequestHead, ByteBuffer>()
|
||||
XCTAssertNoThrow(try channel.pipeline.add(handler: handler).wait())
|
||||
XCTAssertNoThrow(try channel.pipeline.addHandler(handler).wait())
|
||||
|
||||
// Send a POST without a length field of any kind. This should be a zero-length request,
|
||||
// so .end should come immediately.
|
||||
|
||||
Reference in new issue
Block a user