Skip to content

Commit

Permalink
fix request/response
Browse files Browse the repository at this point in the history
  • Loading branch information
tanner0101 committed Jan 27, 2016
1 parent 6d4cae6 commit 98b75ea
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 8 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
Packages
.build
main.swift
main.swift
Public
Resources
2 changes: 1 addition & 1 deletion Sources/Request.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public class Request {
var headers: [String: String] = [:]
var body: [UInt8] = []
var address: String? = ""
var session: Session = Session()
public var session: Session = Session()

init(method: Method) {
self.method = method
Expand Down
6 changes: 3 additions & 3 deletions Sources/Response.swift
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ public class Response {
"error": true,
"message": error
]
try! self.init(status: .Error, jsonObject: object as! AnyObject)
try! self.init(status: .Error, json: object as! AnyObject)
}

convenience init(status: Status, html: String) {
Expand All @@ -180,8 +180,8 @@ public class Response {
self.init(status: status, data: data, contentType: .Text)
}

convenience init(status: Status, jsonObject: Any) throws {
guard let jsonObject = jsonObject as? AnyObject else {
convenience init(status: Status, json: Any) throws {
guard let jsonObject = json as? AnyObject else {
throw SerializationError.InvalidObject
}
guard NSJSONSerialization.isValidJSONObject(jsonObject) else {
Expand Down
4 changes: 2 additions & 2 deletions Sources/ResponseConvertible.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ extension String: ResponseConvertible {
extension Dictionary: ResponseConvertible {
public func response() -> Response {
do {
return try Response(status: .OK, jsonObject: self)
return try Response(status: .OK, json: self)
} catch {
return Response(error: "JSON serialization error: \(error)")
}
Expand All @@ -25,7 +25,7 @@ extension Dictionary: ResponseConvertible {
extension Array: ResponseConvertible {
public func response() -> Response {
do {
return try Response(status: .OK, jsonObject: (self as! AnyObject))
return try Response(status: .OK, json: (self as! AnyObject))
} catch {
return Response(error: "JSON serialization error: \(error)")
}
Expand Down
3 changes: 2 additions & 1 deletion Sources/Server.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@ public class Server: SocketServer {
for route in Route.routes {
self.router.register(route.method.rawValue, path: route.path) { request in


//grab request params
let routePaths = route.path.split("/")
let routePaths = route.path.split("?")[0].split("/")
for (index, path) in routePaths.enumerate() {
if path.hasPrefix(":") {
let requestPaths = request.path.split("/")
Expand Down

0 comments on commit 98b75ea

Please sign in to comment.