Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion Sources/DemoServer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -154,9 +154,13 @@ public func demoServer(_ publicDir: String) -> HttpServer {
return HttpResponse.raw(200, "OK", ["XXX-Custom-Header": "value"], { try $0.write([UInt8]("test".utf8)) })
}

server["/redirect"] = { r in
server["/redirect/permanently"] = { r in
return .movedPermanently("http://www.google.com")
}

server["/redirect/temporarily"] = { r in
return .movedTemporarily("http://www.google.com")
}

server["/long"] = { r in
var longResponse = ""
Expand Down
5 changes: 5 additions & 0 deletions Sources/HttpResponse.swift
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ public enum HttpResponse {
case switchProtocols([String: String], (Socket) -> Void)
case ok(HttpResponseBody), created, accepted
case movedPermanently(String)
case movedTemporarily(String)
case badRequest(HttpResponseBody?), unauthorized, forbidden, notFound
case internalServerError
case raw(Int, String, [String:String]?, ((HttpResponseBodyWriter) throws -> Void)? )
Expand All @@ -93,6 +94,7 @@ public enum HttpResponse {
case .created : return 201
case .accepted : return 202
case .movedPermanently : return 301
case .movedTemporarily : return 307
case .badRequest(_) : return 400
case .unauthorized : return 401
case .forbidden : return 403
Expand All @@ -109,6 +111,7 @@ public enum HttpResponse {
case .created : return "Created"
case .accepted : return "Accepted"
case .movedPermanently : return "Moved Permanently"
case .movedTemporarily : return "Moved Temporarily"
case .badRequest(_) : return "Bad Request"
case .unauthorized : return "Unauthorized"
case .forbidden : return "Forbidden"
Expand All @@ -133,6 +136,8 @@ public enum HttpResponse {
}
case .movedPermanently(let location):
headers["Location"] = location
case .movedTemporarily(let location):
headers["Location"] = location
case .raw(_, _, let rawHeaders, _):
if let rawHeaders = rawHeaders {
for (k, v) in rawHeaders {
Expand Down