Skip to content
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

Resolves an infinite loop when receiving data #182

Merged
merged 1 commit into from
Apr 16, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 5 additions & 14 deletions Sources/Vapor/Server/HTTPStream.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ protocol HTTPStream: Stream {

func listen() throws

func receiveByte() throws -> Byte
func receiveByte() throws -> Byte?
func receiveLine() throws -> String

func sendHeaderEndOfLine() throws
Expand All @@ -26,31 +26,22 @@ protocol HTTPStream: Stream {
}

extension HTTPStream {
func receiveByte() throws -> Byte {
repeat {
if let byte = try receive(max: 1).first {
return byte
}
} while true
func receiveByte() throws -> Byte? {
return try receive(max: 1).first
}

func receiveLine() throws -> String {
var line: String = ""

func append(byte: Byte?) {
guard let byte = byte else {
return
}
func append(byte: Byte) {
guard byte >= minimumValidAsciiCharacter else {
return
}

line.append(Character(byte))
}

var byte: Byte?
while byte != newLine && !closed {
byte = try receiveByte()
while !closed, let byte = try receiveByte() where byte != newLine {
append(byte)
}

Expand Down