From 31591b8cd51a39d59c2749da8b264f9ecb2bfff7 Mon Sep 17 00:00:00 2001 From: Michael Bykovski Date: Wed, 12 Jul 2017 10:45:05 +0200 Subject: [PATCH] Fixed Body interpretation for requests --- src/ios/Webserver.swift | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/src/ios/Webserver.swift b/src/ios/Webserver.swift index c3ded78..88e7c77 100644 --- a/src/ios/Webserver.swift +++ b/src/ios/Webserver.swift @@ -13,14 +13,21 @@ self.initHTTPRequestHandlers() } - func requestToRequestDict(requestUUID: String, request: GCDWebServerDataRequest) -> Dictionary { + func requestToRequestDict(requestUUID: String, request: GCDWebServerRequest) -> Dictionary { + let dataRequest = request as! GCDWebServerDataRequest + var body = "" + + if dataRequest.hasBody() { + body = String(data: dataRequest.data, encoding: String.Encoding(rawValue: String.Encoding.utf8.rawValue)) ?? "" + } + return [ "requestId": requestUUID, - "body": request.text ?? "", - "headers": request.headers, - "method": request.method, - "path": request.url.path, - "query": request.url.query ?? "" + "body": body, + "headers": dataRequest.headers, + "method": dataRequest.method, + "path": dataRequest.url.path, + "query": dataRequest.url.query ?? "" ] } @@ -29,7 +36,7 @@ // Fetch data as GCDWebserverDataRequest let requestUUID = UUID().uuidString // 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 if (self.onRequestCommand != nil) {