Skip to content

Commit

Permalink
Updated Swift and S4 (#10)
Browse files Browse the repository at this point in the history
* Updated Swift and S4

* use single headers
  • Loading branch information
czechboy0 committed Jun 4, 2016
1 parent 53805b4 commit 6d212c2
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 16 deletions.
2 changes: 1 addition & 1 deletion .swift-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
DEVELOPMENT-SNAPSHOT-2016-05-03-a
DEVELOPMENT-SNAPSHOT-2016-05-31-a
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ osx_image: xcode7.3
install:
- eval "$(curl -sL https://raw.githubusercontent.com/Zewo/Zewo/5254525d9da56df29346fd76e99529c22034d61d/Scripts/install-swiftenv.sh)"
script:
- swift build -Xlinker -rpath -Xlinker $(pwd)/.build/debug/
- swift build --configuration release -Xlinker -rpath -Xlinker $(pwd)/.build/release/
- swift build
- swift build --configuration release
- swift test
4 changes: 2 additions & 2 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import PackageDescription
let package = Package(
name: "HTTPSerializer",
dependencies: [
.Package(url: "https://github.com/open-swift/S4.git", majorVersion: 0, minor: 6),
.Package(url: "https://github.com/Zewo/URI.git", majorVersion: 0, minor: 7)
.Package(url: "https://github.com/open-swift/S4.git", majorVersion: 0, minor: 9),
.Package(url: "https://github.com/Zewo/URI.git", majorVersion: 0, minor: 8)
]
)
31 changes: 31 additions & 0 deletions Sources/Cookie.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
extension Cookie: CustomStringConvertible {
public var description: String {
var string = "\(name)=\(value)"

if let expires = expires {
string += "; Expires=\(expires)"
}

if let maxAge = maxAge {
string += "; Max-Age=\(maxAge)"
}

if let domain = domain {
string += "; Domain=\(domain)"
}

if let path = path {
string += "; Path=\(path)"
}

if secure {
string += "; Secure"
}

if HTTPOnly {
string += "; HttpOnly"
}

return string
}
}
10 changes: 5 additions & 5 deletions Sources/RequestSerializer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,9 @@ public struct RequestSerializer: S4.RequestSerializer {
try transport.send("\(request.method) \(request.uri.percentEncoded()) HTTP/\(request.version.major).\(request.version.minor)".data, timingOut: .never)
try transport.send(newLine)

for (name, values) in request.headers.headers {
for value in values.values {
try transport.send("\(name): \(value)".data)
try transport.send(newLine)
}
for (name, value) in request.headers.headers {
try transport.send("\(name): \(value)".data)
try transport.send(newLine)
}

try transport.send(newLine)
Expand All @@ -65,6 +63,8 @@ public struct RequestSerializer: S4.RequestSerializer {
try transport.send("0".data)
try transport.send(newLine)
try transport.send(newLine)
default:
throw BodyError.inconvertibleType
}

try transport.flush()
Expand Down
15 changes: 10 additions & 5 deletions Sources/ResponseSerializer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,14 @@ public struct ResponseSerializer: S4.ResponseSerializer {
try transport.send("HTTP/\(response.version.major).\(response.version.minor) \(response.status.statusCode) \(response.status.reasonPhrase)".data)
try transport.send(newLine)

for (name, values) in response.headers.headers {
for value in values.values {
try transport.send("\(name): \(value)".data)
try transport.send(newLine)
}
for (name, value) in response.headers.headers {
try transport.send("\(name): \(value)".data)
try transport.send(newLine)
}

for cookie in response.cookies {
try transport.send("Set-Cookie: \(cookie)".data)
try transport.send(newLine)
}

try transport.send(newLine)
Expand All @@ -64,6 +67,8 @@ public struct ResponseSerializer: S4.ResponseSerializer {
try transport.send("0".data)
try transport.send(newLine)
try transport.send(newLine)
default:
throw BodyError.inconvertibleType
}

try transport.flush()
Expand Down
2 changes: 1 addition & 1 deletion Tests/HTTPSerializer/HTTPSerializerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class HTTPSerializerTests: XCTestCase {
}

extension HTTPSerializerTests {
static var allTests: [(String, HTTPSerializerTests -> () throws -> Void)] {
static var allTests: [(String, (HTTPSerializerTests) -> () throws -> Void)] {
return [
("testReality", testReality),
]
Expand Down

0 comments on commit 6d212c2

Please sign in to comment.