Skip to content

Commit febcee7

Browse files
authored
Merge pull request #352 from csch/stable
Add .movedTemporarily case (HTTP 307) to HttpResponse
2 parents 9c25524 + c8977ff commit febcee7

2 files changed

Lines changed: 10 additions & 1 deletion

File tree

Sources/DemoServer.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,9 +154,13 @@ public func demoServer(_ publicDir: String) -> HttpServer {
154154
return HttpResponse.raw(200, "OK", ["XXX-Custom-Header": "value"], { try $0.write([UInt8]("test".utf8)) })
155155
}
156156

157-
server["/redirect"] = { r in
157+
server["/redirect/permanently"] = { r in
158158
return .movedPermanently("http://www.google.com")
159159
}
160+
161+
server["/redirect/temporarily"] = { r in
162+
return .movedTemporarily("http://www.google.com")
163+
}
160164

161165
server["/long"] = { r in
162166
var longResponse = ""

Sources/HttpResponse.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ public enum HttpResponse {
8282
case switchProtocols([String: String], (Socket) -> Void)
8383
case ok(HttpResponseBody), created, accepted
8484
case movedPermanently(String)
85+
case movedTemporarily(String)
8586
case badRequest(HttpResponseBody?), unauthorized, forbidden, notFound
8687
case internalServerError
8788
case raw(Int, String, [String:String]?, ((HttpResponseBodyWriter) throws -> Void)? )
@@ -93,6 +94,7 @@ public enum HttpResponse {
9394
case .created : return 201
9495
case .accepted : return 202
9596
case .movedPermanently : return 301
97+
case .movedTemporarily : return 307
9698
case .badRequest(_) : return 400
9799
case .unauthorized : return 401
98100
case .forbidden : return 403
@@ -109,6 +111,7 @@ public enum HttpResponse {
109111
case .created : return "Created"
110112
case .accepted : return "Accepted"
111113
case .movedPermanently : return "Moved Permanently"
114+
case .movedTemporarily : return "Moved Temporarily"
112115
case .badRequest(_) : return "Bad Request"
113116
case .unauthorized : return "Unauthorized"
114117
case .forbidden : return "Forbidden"
@@ -133,6 +136,8 @@ public enum HttpResponse {
133136
}
134137
case .movedPermanently(let location):
135138
headers["Location"] = location
139+
case .movedTemporarily(let location):
140+
headers["Location"] = location
136141
case .raw(_, _, let rawHeaders, _):
137142
if let rawHeaders = rawHeaders {
138143
for (k, v) in rawHeaders {

0 commit comments

Comments
 (0)