I'm playing with GCDWebServer
class (it is great!) and was wondering if it is possible to limit allowed connections by remote IP.
server.addDefaultHandlerForMethod("GET", requestClass: GCDWebServerRequest.self, processBlock: {request in
let remote = request.remoteAddressString.substringToIndex(request.remoteAddressString.lastIndexOf(":")!)
let local = request.localAddressString.substringToIndex(request.localAddressString.lastIndexOf(":")!)
print("\(remote) vs \(local)")
if remote == local {
return nil
}
//Forbidden
return GCDWebServerResponse(statusCode: 403);
})
I hoped above will work but it isnt, I mean it sends 403 Forbidden when IP's are different but otherwise it ends up with:
[DEBUG] Connection aborted with status code 500 on socket 13
Can anyone help me with this?
P.S. following also doenst work
server.addDefaultHandlerForMethod("GET",
requestClass: GCDWebServerRequest.self,
processBlock: {request in
print(request.remoteAddressString)
print(request.localAddressString)
let remote = request.remoteAddressString.substringToIndex(request.remoteAddressString.lastIndexOf(":")!)
let local = request.localAddressString.substringToIndex(request.localAddressString.lastIndexOf(":")!)
print("\(remote) vs \(local)")
if remote == local {
return GCDWebServerResponse(statusCode: 200)
}
//Forbidden
return GCDWebServerResponse(statusCode: 403);
})