Fixed Body interpretation for requests

This commit is contained in:
Michael Bykovski 2017-07-12 10:45:05 +02:00
parent d091dc88cd
commit 31591b8cd5

View File

@ -13,14 +13,21 @@
self.initHTTPRequestHandlers() self.initHTTPRequestHandlers()
} }
func requestToRequestDict(requestUUID: String, request: GCDWebServerDataRequest) -> Dictionary<String, Any> { func requestToRequestDict(requestUUID: String, request: GCDWebServerRequest) -> Dictionary<String, Any> {
let dataRequest = request as! GCDWebServerDataRequest
var body = ""
if dataRequest.hasBody() {
body = String(data: dataRequest.data, encoding: String.Encoding(rawValue: String.Encoding.utf8.rawValue)) ?? ""
}
return [ return [
"requestId": requestUUID, "requestId": requestUUID,
"body": request.text ?? "", "body": body,
"headers": request.headers, "headers": dataRequest.headers,
"method": request.method, "method": dataRequest.method,
"path": request.url.path, "path": dataRequest.url.path,
"query": request.url.query ?? "" "query": dataRequest.url.query ?? ""
] ]
} }
@ -29,7 +36,7 @@
// Fetch data as GCDWebserverDataRequest // Fetch data as GCDWebserverDataRequest
let requestUUID = UUID().uuidString let requestUUID = UUID().uuidString
// Transform it into an dictionary for the javascript plugin // Transform it into an dictionary for the javascript plugin
let requestDict = self.requestToRequestDict(requestUUID: requestUUID, request: request as! GCDWebServerDataRequest) let requestDict = self.requestToRequestDict(requestUUID: requestUUID, request: request)
// Do a call to the onRequestCommand to inform the JS plugin // Do a call to the onRequestCommand to inform the JS plugin
if (self.onRequestCommand != nil) { if (self.onRequestCommand != nil) {