Skip to content

Commit

Permalink
Prevent collision on HTTPParser state by consecutive keepalive reques…
Browse files Browse the repository at this point in the history
…ts (#227)
  • Loading branch information
djones6 authored and tunniclm committed Nov 3, 2017
1 parent 5fd7b5c commit c29812e
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions Sources/KituraNet/HTTP/HTTPServerResponse.swift
Original file line number Diff line number Diff line change
Expand Up @@ -107,23 +107,22 @@ public class HTTPServerResponse : ServerResponse {
public func end() throws {
if let processor = processor {
try flushStart()

let keepAlive = processor.isKeepAlive

if keepAlive {
processor.keepAlive()
}

if buffer.length > 0 {
processor.write(from: buffer)
}

let keepAlive = processor.isKeepAlive
if !keepAlive && !processor.isUpgrade {
processor.close()
}
if let request = request {
Monitor.delegate?.finished(request: request, response: self)
}
// Ordering is important here. Keepalive allows the processor to continue
// processing further requests, so must only be called once monitoring
// has completed, as the HTTPParser for this connection is reused.
if keepAlive {
processor.keepAlive()
}
}
}

Expand Down

0 comments on commit c29812e

Please sign in to comment.