{"action":"created","issue":{"url":"https://api.github.com/repos/vapor/vapor/issues/1596","repository_url":"https://api.github.com/repos/vapor/vapor","labels_url":"https://api.github.com/repos/vapor/vapor/issues/1596/labels{/name}","comments_url":"https://api.github.com/repos/vapor/vapor/issues/1596/comments","events_url":"https://api.github.com/repos/vapor/vapor/issues/1596/events","html_url":"https://github.com/vapor/vapor/issues/1596","id":310160212,"number":1596,"title":"FoundationClient Not Using URL Correctly","user":{"login":"instig","id":37941013,"avatar_url":"https://avatars2.githubusercontent.com/u/37941013?v=4","gravatar_id":"","url":"https://api.github.com/users/instig","html_url":"https://github.com/instig","followers_url":"https://api.github.com/users/instig/followers","following_url":"https://api.github.com/users/instig/following{/other_user}","gists_url":"https://api.github.com/users/instig/gists{/gist_id}","starred_url":"https://api.github.com/users/instig/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/instig/subscriptions","organizations_url":"https://api.github.com/users/instig/orgs","repos_url":"https://api.github.com/users/instig/repos","events_url":"https://api.github.com/users/instig/events{/privacy}","received_events_url":"https://api.github.com/users/instig/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":7,"created_at":"2018-03-30T20:23:48Z","updated_at":"2018-04-02T19:38:19Z","closed_at":null,"author_association":"NONE","body":"<!-- 🚀 Thank you for contributing! --->\r\n\r\nUsing the FoundationClient to send a URL request will return the error: **cannot decode raw data** when returned from a route.\r\n<!-- Provide a brief description of the issue here. -->\r\n<!-- Pretend you are explaining it to a friend, not yourself! -->\r\n\r\n### Steps to reproduce\r\n\r\nSuppose we have a function that takes in a URL, and returns a response from the website:\r\n\r\n```swift\r\n func send(request: Request, toURL url: URL) throws -> EventLoopFuture<Response> {\r\n        return try request.make(Client.self).get(url)\r\n }  \r\n```\r\n\r\nNext, create a route that uses the function above, as a return value:\r\n\r\n```swift\r\nfunc example(_ req: Request) throws -> Future<Response> {\r\n        let requestURL = URL(string: \"http://UrlToObtainDataFrom\")\r\n        let response = try send(request: req, toURL: requestURL!)\r\n        _ = response.do { (newResponse) in\r\n            print(\"response: \", newResponse)\r\n        }\r\n        return response\r\n }\r\n```\r\n\r\n(Note: the requestURL is a placeholder URL, and you should replace the URL there with a valid website that you can obtain data from).\r\n\r\nUpon calling the route `example`, it will print out the correct response, however: the returned data returns the error **cannot decode raw data**. \r\n\r\nNote(s):\r\n\r\n- Upon sending a request for data to a URL, you are able to print out the response, and it will print the data and headers as expected.\r\n- However, when the data is returned from the route, it will return an error.\r\n- The Client type is FoundationClient.\r\n- It is likely that FoundationClient is not correctly using URL.\r\n\r\nAdditional Note(s)\r\n- Before the latest Vapor update, using URI would correctly return a response. \r\n- Using URL instead of URI, no longer returns the correct response.\r\n\r\n<!-- Tell us how to reproduce this issue. -->\r\n<!-- Please provide as much detail as possible (the more code snippets, the better)! -->\r\n<!-- If we cannot recreate it, we will not be able to figure out how to fix it. -->\r\n\r\n### Expected behavior\r\n\r\nUpon sending a request to a URL for data, it should not return an error if the data is successfully retrieved from the URL. \r\n\r\n<!-- Tell us what you expect to happen (what should happen once we fix the issue). -->\r\n\r\n### Environment\r\n\r\n<!-- We must know your exact environment or it is very difficult to help. -->\r\n<!-- Hint: use `vapor --version` in the root directory of your Vapor project. -->\r\n\r\n* Vapor Framework version: 3.1.4\r\n* Vapor Toolbox version: 3.0.0-rc.2.2.1\r\n* OS version: 10.13.3"},"comment":{"url":"https://api.github.com/repos/vapor/vapor/issues/comments/378021341","html_url":"https://github.com/vapor/vapor/issues/1596#issuecomment-378021341","issue_url":"https://api.github.com/repos/vapor/vapor/issues/1596","id":378021341,"user":{"login":"instig","id":37941013,"avatar_url":"https://avatars2.githubusercontent.com/u/37941013?v=4","gravatar_id":"","url":"https://api.github.com/users/instig","html_url":"https://github.com/instig","followers_url":"https://api.github.com/users/instig/followers","following_url":"https://api.github.com/users/instig/following{/other_user}","gists_url":"https://api.github.com/users/instig/gists{/gist_id}","starred_url":"https://api.github.com/users/instig/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/instig/subscriptions","organizations_url":"https://api.github.com/users/instig/orgs","repos_url":"https://api.github.com/users/instig/repos","events_url":"https://api.github.com/users/instig/events{/privacy}","received_events_url":"https://api.github.com/users/instig/received_events","type":"User","site_admin":false},"created_at":"2018-04-02T19:38:19Z","updated_at":"2018-04-02T19:38:19Z","author_association":"NONE","body":"If I create a new route that returns a String, Postman successfully returns the String."}}
{"actor":{"display_login":"instig"}}