Only forward bytes on removal when we know we can handle it (#430)

Motivation:

398b950eee introduced a change which forwarded bytes that were buffered in HTTPDecoder after it was removed when an upgrade was detected. This may be risky if we dont know that the pipeline can handle it.

Modifications:

- Add new initializer that allow us to configure if we should forward bytes or not.
- Automatically use this if we know that we added an upgrader
- Add unit tests.

Result:

Less risky implementation.
This commit is contained in:
Norman Maurer authored and GitHub committed 2018-05-23 20:26:24 +02:00
1 parent 9e0eb8347a
commit d53ee6dafc
5 files changed
+104 -10

No files matched your search

+3 -3
View File
@@ -140,15 +140,15 @@ public class HTTPServerUpgradeHandler: ChannelInboundHandler {
if let upgrade = self.upgrade {
switch requestPart {
case .head(_):
case .head:
ctx.fireErrorCaught(HTTPUpgradeErrors.invalidHTTPOrdering)
notUpgrading(ctx: ctx, data: data)
return
case .body(_):
case .body:
// TODO: In the future way may want to add some API to also allow special handling of the body during the
// upgrade. For now just ignore it.
break
case .end(_):
case .end:
self.seenFirstRequest = true
// The request is complete now trigger the upgrade.