mirror of
https://github.com/apple/swift-nio
synced 2026-11-26 04:57:49 +00:00
remove redundant labels
Motivation:
Lots of our most important operations had redundant labels like
func write(data: NIOAny)
the `data: ` label doesn't add anything meaningful and therefore it
should be removed.
Modifications:
removed lots of redundant labels
Result:
less redundant labels
This commit is contained in:
1 parent
dba0a5379c
commit
eaa8ffaee4
35 files changed
+335
-335
No files matched your search
@@ -195,7 +195,7 @@ public final class HTTPResponseDecoder: HTTPDecoder<HTTPClientResponsePart>, Cha
|
||||
break
|
||||
}
|
||||
|
||||
ctx.write(data: data, promise: promise)
|
||||
ctx.write(data, promise: promise)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -273,13 +273,13 @@ public class HTTPDecoder<HTTPMessageT>: ByteToMessageDecoder, AnyHTTPDecoder {
|
||||
case let handler as HTTPRequestDecoder:
|
||||
let head = handler.newRequestHead(parser)
|
||||
handler.pendingCallouts.append {
|
||||
ctx.fireChannelRead(data: handler.wrapInboundOut(HTTPServerRequestPart.head(head)))
|
||||
ctx.fireChannelRead(handler.wrapInboundOut(HTTPServerRequestPart.head(head)))
|
||||
}
|
||||
return 0
|
||||
case let handler as HTTPResponseDecoder:
|
||||
let head = handler.newResponseHead(parser)
|
||||
handler.pendingCallouts.append {
|
||||
ctx.fireChannelRead(data: handler.wrapInboundOut(HTTPClientResponsePart.head(head)))
|
||||
ctx.fireChannelRead(handler.wrapInboundOut(HTTPClientResponsePart.head(head)))
|
||||
}
|
||||
|
||||
// http_parser doesn't correctly handle responses to HEAD requests. We have to do something
|
||||
@@ -311,9 +311,9 @@ public class HTTPDecoder<HTTPMessageT>: ByteToMessageDecoder, AnyHTTPDecoder {
|
||||
handler.pendingCallouts.append {
|
||||
switch handler {
|
||||
case let handler as HTTPRequestDecoder:
|
||||
ctx.fireChannelRead(data: handler.wrapInboundOut(HTTPServerRequestPart.body(slice)))
|
||||
ctx.fireChannelRead(handler.wrapInboundOut(HTTPServerRequestPart.body(slice)))
|
||||
case let handler as HTTPResponseDecoder:
|
||||
ctx.fireChannelRead(data: handler.wrapInboundOut(HTTPClientResponsePart.body(slice)))
|
||||
ctx.fireChannelRead(handler.wrapInboundOut(HTTPClientResponsePart.body(slice)))
|
||||
default:
|
||||
fatalError("the impossible happened: handler neither a HTTPRequestDecoder nor a HTTPResponseDecoder which should be impossible")
|
||||
}
|
||||
@@ -373,9 +373,9 @@ public class HTTPDecoder<HTTPMessageT>: ByteToMessageDecoder, AnyHTTPDecoder {
|
||||
handler.pendingCallouts.append {
|
||||
switch handler {
|
||||
case let handler as HTTPRequestDecoder:
|
||||
ctx.fireChannelRead(data: handler.wrapInboundOut(HTTPServerRequestPart.end(trailers)))
|
||||
ctx.fireChannelRead(handler.wrapInboundOut(HTTPServerRequestPart.end(trailers)))
|
||||
case let handler as HTTPResponseDecoder:
|
||||
ctx.fireChannelRead(data: handler.wrapInboundOut(HTTPClientResponsePart.end(trailers)))
|
||||
ctx.fireChannelRead(handler.wrapInboundOut(HTTPClientResponsePart.end(trailers)))
|
||||
default:
|
||||
fatalError("the impossible happened: handler neither a HTTPRequestDecoder nor a HTTPResponseDecoder which should be impossible")
|
||||
}
|
||||
@@ -444,7 +444,7 @@ public class HTTPDecoder<HTTPMessageT>: ByteToMessageDecoder, AnyHTTPDecoder {
|
||||
}
|
||||
|
||||
public func errorCaught(ctx: ChannelHandlerContext, error: Error) {
|
||||
ctx.fireErrorCaught(error: error)
|
||||
ctx.fireErrorCaught(error)
|
||||
if error is HTTPParserError {
|
||||
ctx.close(promise: nil)
|
||||
}
|
||||
|
||||
@@ -40,15 +40,15 @@ private func writeChunk(wrapOutboundOut: (IOData) -> NIOAny, ctx: ChannelHandler
|
||||
let len = String(readableBytes, radix: 16)
|
||||
buffer.write(string: len)
|
||||
buffer.write(staticString: "\r\n")
|
||||
ctx.write(data: wrapOutboundOut(.byteBuffer(buffer)), promise: mW1)
|
||||
ctx.write(wrapOutboundOut(.byteBuffer(buffer)), promise: mW1)
|
||||
|
||||
ctx.write(data: wrapOutboundOut(chunk), promise: mW2)
|
||||
ctx.write(wrapOutboundOut(chunk), promise: mW2)
|
||||
|
||||
// Just move the buffers readerIndex to only make the \r\n readable and depend on COW semantics.
|
||||
buffer.moveReaderIndex(forwardBy: buffer.readableBytes - 2)
|
||||
ctx.write(data: wrapOutboundOut(.byteBuffer(buffer)), promise: mW3)
|
||||
ctx.write(wrapOutboundOut(.byteBuffer(buffer)), promise: mW3)
|
||||
} else {
|
||||
ctx.write(data: wrapOutboundOut(chunk), promise: mW2)
|
||||
ctx.write(wrapOutboundOut(chunk), promise: mW2)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -64,12 +64,12 @@ private func writeTrailers(wrapOutboundOut: (IOData) -> NIOAny, ctx: ChannelHand
|
||||
buffer = ctx.channel.allocator.buffer(capacity: 8)
|
||||
buffer.write(staticString: "0\r\n\r\n")
|
||||
}
|
||||
ctx.write(data: wrapOutboundOut(.byteBuffer(buffer)), promise: p)
|
||||
ctx.write(wrapOutboundOut(.byteBuffer(buffer)), promise: p)
|
||||
case (false, .some(let p)):
|
||||
// Not chunked so we have nothing to write. However, we don't want to satisfy this promise out-of-order
|
||||
// so we issue a zero-length write down the chain.
|
||||
let buf = ctx.channel.allocator.buffer(capacity: 0)
|
||||
ctx.write(data: wrapOutboundOut(.byteBuffer(buf)), promise: p)
|
||||
ctx.write(wrapOutboundOut(.byteBuffer(buf)), promise: p)
|
||||
case (false, .none):
|
||||
break
|
||||
}
|
||||
@@ -80,7 +80,7 @@ private func writeHead(wrapOutboundOut: (IOData) -> NIOAny, writeStartLine: (ino
|
||||
var buffer = ctx.channel.allocator.buffer(capacity: 256)
|
||||
writeStartLine(&buffer)
|
||||
headers.write(buffer: &buffer)
|
||||
ctx.write(data: wrapOutboundOut(.byteBuffer(buffer)), promise: promise)
|
||||
ctx.write(wrapOutboundOut(.byteBuffer(buffer)), promise: promise)
|
||||
}
|
||||
|
||||
private func isChunkedPart(_ headers: HTTPHeaders) -> Bool {
|
||||
|
||||
@@ -97,7 +97,7 @@ public final class HTTPResponseCompressor: ChannelInboundHandler, ChannelOutboun
|
||||
default:
|
||||
break
|
||||
}
|
||||
ctx.fireChannelRead(data: data)
|
||||
ctx.fireChannelRead(data)
|
||||
}
|
||||
|
||||
public func write(ctx: ChannelHandlerContext, data: NIOAny, promise: EventLoopPromise<Void>?) {
|
||||
@@ -106,7 +106,7 @@ public final class HTTPResponseCompressor: ChannelInboundHandler, ChannelOutboun
|
||||
case .head(var responseHead):
|
||||
algorithm = compressionAlgorithm()
|
||||
guard algorithm != nil else {
|
||||
ctx.write(data: wrapOutboundOut(.head(responseHead)), promise: promise)
|
||||
ctx.write(wrapOutboundOut(.head(responseHead)), promise: promise)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -119,13 +119,13 @@ public final class HTTPResponseCompressor: ChannelInboundHandler, ChannelOutboun
|
||||
pendingResponse.bufferBodyPart(body)
|
||||
chainPromise(promise)
|
||||
} else {
|
||||
ctx.write(data: data, promise: promise)
|
||||
ctx.write(data, promise: promise)
|
||||
}
|
||||
case .end:
|
||||
// This compress is not done in flush because we need to be done with the
|
||||
// compressor now.
|
||||
guard algorithm != nil else {
|
||||
ctx.write(data: data, promise: promise)
|
||||
ctx.write(data, promise: promise)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -216,17 +216,17 @@ public final class HTTPResponseCompressor: ChannelInboundHandler, ChannelOutboun
|
||||
var pendingPromise = pendingWritePromise
|
||||
|
||||
if let writeHead = writesToEmit.0 {
|
||||
ctx.write(data: wrapOutboundOut(.head(writeHead)), promise: pendingPromise)
|
||||
ctx.write(wrapOutboundOut(.head(writeHead)), promise: pendingPromise)
|
||||
pendingPromise = nil
|
||||
}
|
||||
|
||||
if let writeBody = writesToEmit.1 {
|
||||
ctx.write(data: wrapOutboundOut(.body(.byteBuffer(writeBody))), promise: pendingPromise)
|
||||
ctx.write(wrapOutboundOut(.body(.byteBuffer(writeBody))), promise: pendingPromise)
|
||||
pendingPromise = nil
|
||||
}
|
||||
|
||||
if let writeEnd = writesToEmit.2 {
|
||||
ctx.write(data: wrapOutboundOut(writeEnd), promise: pendingPromise)
|
||||
ctx.write(wrapOutboundOut(writeEnd), promise: pendingPromise)
|
||||
pendingPromise = nil
|
||||
}
|
||||
|
||||
|
||||
@@ -86,7 +86,7 @@ public class HTTPServerUpgradeHandler: ChannelInboundHandler {
|
||||
public func channelRead(ctx: ChannelHandlerContext, data: NIOAny) {
|
||||
// We're trying to remove ourselves from the pipeline, so just pass this on.
|
||||
if seenFirstRequest {
|
||||
ctx.fireChannelRead(data: data)
|
||||
ctx.fireChannelRead(data)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -96,7 +96,7 @@ public class HTTPServerUpgradeHandler: ChannelInboundHandler {
|
||||
// We should only ever see a request header: by the time the body comes in we should
|
||||
// be out of the pipeline. Anything else is an error.
|
||||
guard case .head(let request) = requestPart else {
|
||||
ctx.fireErrorCaught(error: HTTPUpgradeErrors.invalidHTTPOrdering)
|
||||
ctx.fireErrorCaught(HTTPUpgradeErrors.invalidHTTPOrdering)
|
||||
notUpgrading(ctx: ctx, data: data)
|
||||
return
|
||||
}
|
||||
@@ -135,14 +135,14 @@ public class HTTPServerUpgradeHandler: ChannelInboundHandler {
|
||||
responseHeaders = try upgrader.buildUpgradeResponse(upgradeRequest: request, initialResponseHeaders: responseHeaders)
|
||||
} catch {
|
||||
// We should fire this error so the user can log it, but keep going.
|
||||
ctx.fireErrorCaught(error: error)
|
||||
ctx.fireErrorCaught(error)
|
||||
continue
|
||||
}
|
||||
|
||||
sendUpgradeResponse(ctx: ctx, upgradeRequest: request, responseHeaders: responseHeaders).whenSuccess {
|
||||
self.upgradeCompletionHandler(ctx)
|
||||
upgrader.upgrade(ctx: ctx, upgradeRequest: request)
|
||||
ctx.fireUserInboundEventTriggered(event: HTTPUpgradeEvents.upgradeComplete(toProtocol: proto, upgradeRequest: request))
|
||||
ctx.fireUserInboundEventTriggered(HTTPUpgradeEvents.upgradeComplete(toProtocol: proto, upgradeRequest: request))
|
||||
let _ = ctx.pipeline.remove(ctx: ctx)
|
||||
}
|
||||
|
||||
@@ -156,12 +156,12 @@ public class HTTPServerUpgradeHandler: ChannelInboundHandler {
|
||||
private func sendUpgradeResponse(ctx: ChannelHandlerContext, upgradeRequest: HTTPRequestHead, responseHeaders: HTTPHeaders) -> EventLoopFuture<Void> {
|
||||
var response = HTTPResponseHead(version: HTTPVersion(major: 1, minor: 1), status: .switchingProtocols)
|
||||
response.headers = responseHeaders
|
||||
return ctx.writeAndFlush(data: wrapOutboundOut(HTTPServerResponsePart.head(response)))
|
||||
return ctx.writeAndFlush(wrapOutboundOut(HTTPServerResponsePart.head(response)))
|
||||
}
|
||||
|
||||
/// Called when we know we're not upgrading. Passes the data on and then removes this object from the pipeline.
|
||||
private func notUpgrading(ctx: ChannelHandlerContext, data: NIOAny) {
|
||||
ctx.fireChannelRead(data: data)
|
||||
ctx.fireChannelRead(data)
|
||||
let _ = ctx.pipeline.remove(ctx: ctx)
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user