|
@@ -44,11 +44,11 @@ class HttpServer
|
|
|
if let regex = NSRegularExpression.regularExpressionWithPattern(path, options: expressionOptions, error: nil) {
|
|
if let regex = NSRegularExpression.regularExpressionWithPattern(path, options: expressionOptions, error: nil) {
|
|
|
handlers.append(expression: regex, handler: { (method, path, headers, responseData) in
|
|
handlers.append(expression: regex, handler: { (method, path, headers, responseData) in
|
|
|
let result = regex.firstMatchInString(path, options: self.matchingOptions, range: NSMakeRange(0, path.lengthOfBytesUsingEncoding(NSASCIIStringEncoding)))
|
|
let result = regex.firstMatchInString(path, options: self.matchingOptions, range: NSMakeRange(0, path.lengthOfBytesUsingEncoding(NSASCIIStringEncoding)))
|
|
|
- let myPath: NSString = path
|
|
|
|
|
- let filesPath = directoryPath.stringByAppendingPathComponent(myPath.substringWithRange(result.rangeAtIndex(1)))
|
|
|
|
|
- if let fileBody = String.stringWithContentsOfFile(filesPath, encoding: NSASCIIStringEncoding, error: nil) {
|
|
|
|
|
- return HttpResponse.OK(.RAW(fileBody))
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ let myPath: NSString = path
|
|
|
|
|
+ let filesPath = directoryPath.stringByAppendingPathComponent(myPath.substringWithRange(result.rangeAtIndex(1)))
|
|
|
|
|
+ if let fileBody = String.stringWithContentsOfFile(filesPath, encoding: NSASCIIStringEncoding, error: nil) {
|
|
|
|
|
+ return HttpResponse.OK(.RAW(fileBody))
|
|
|
|
|
+ }
|
|
|
return HttpResponse.NotFound
|
|
return HttpResponse.NotFound
|
|
|
})
|
|
})
|
|
|
}
|
|
}
|
|
@@ -92,9 +92,9 @@ class HttpServer
|
|
|
Socket.writeStringUTF8(socket, string: "HTTP/1.1 \(response.statusCode()) \(response.reasonPhrase())\r\n")
|
|
Socket.writeStringUTF8(socket, string: "HTTP/1.1 \(response.statusCode()) \(response.reasonPhrase())\r\n")
|
|
|
let messageBody = response.body()
|
|
let messageBody = response.body()
|
|
|
if let body = messageBody {
|
|
if let body = messageBody {
|
|
|
- if let nsdata = body.dataUsingEncoding(NSUTF8StringEncoding) {
|
|
|
|
|
- Socket.writeStringUTF8(socket, string: "Content-Length: \(nsdata.length)\r\n")
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ if let nsdata = body.dataUsingEncoding(NSUTF8StringEncoding) {
|
|
|
|
|
+ Socket.writeStringUTF8(socket, string: "Content-Length: \(nsdata.length)\r\n")
|
|
|
|
|
+ }
|
|
|
} else {
|
|
} else {
|
|
|
Socket.writeStringUTF8(socket, string: "Content-Length: 0\r\n")
|
|
Socket.writeStringUTF8(socket, string: "Content-Length: 0\r\n")
|
|
|
}
|
|
}
|