{"action":"created","issue":{"url":"https://api.github.com/repos/request/request/issues/2632","repository_url":"https://api.github.com/repos/request/request","labels_url":"https://api.github.com/repos/request/request/issues/2632/labels{/name}","comments_url":"https://api.github.com/repos/request/request/issues/2632/comments","events_url":"https://api.github.com/repos/request/request/issues/2632/events","html_url":"https://github.com/request/request/issues/2632","id":220441173,"number":2632,"title":"TypeError: The header content contains invalid characters","user":{"login":"ekkis","id":274980,"avatar_url":"https://avatars3.githubusercontent.com/u/274980?v=4","gravatar_id":"","url":"https://api.github.com/users/ekkis","html_url":"https://github.com/ekkis","followers_url":"https://api.github.com/users/ekkis/followers","following_url":"https://api.github.com/users/ekkis/following{/other_user}","gists_url":"https://api.github.com/users/ekkis/gists{/gist_id}","starred_url":"https://api.github.com/users/ekkis/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ekkis/subscriptions","organizations_url":"https://api.github.com/users/ekkis/orgs","repos_url":"https://api.github.com/users/ekkis/repos","events_url":"https://api.github.com/users/ekkis/events{/privacy}","received_events_url":"https://api.github.com/users/ekkis/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":2,"created_at":"2017-04-09T02:04:45Z","updated_at":"2018-03-17T06:32:13Z","closed_at":null,"author_association":"NONE","body":"### Summary\r\nI recently added a method to the Object prototype and a day later spent a couple of hours fighting with uploads that mysteriously stopped working\r\n\r\n### Simplest Example to Reproduce\r\nthe following works fine:\r\n\r\n```js\r\nconst fs = require('fs');\r\nconst request = require('request');\r\n\r\nvar url = 'http://localhost:8000/';\r\nvar formData = { script: fs.createReadStream('t.txt') };\r\nrequest.post({url, formData}, (err, resp, body) => {\r\n        console.log(err || 'ok');\r\n});\r\n```\r\n\r\nhowever, this fails:\r\n\r\n```js\r\nconst fs = require('fs');\r\nconst request = require('request');\r\n\r\nObject.prototype.XYZ = function() {\r\n    return 0;\r\n}\r\nvar url = 'http://localhost:8000/';\r\nvar formData = { script: fs.createReadStream('t.txt') };\r\nrequest.post({url, formData}, (err, resp, body) => {\r\n        console.log(err || 'ok');\r\n});\r\n```\r\n\r\ninterestingly, it seems to be the newlines in the body of the method that break the code i.e. defining the method this way does not express the problem:\r\n\r\n`Object.prototype.XYZ = function() { return 0; }`\r\n\r\n### Expected Behavior\r\nwhat I would expect happen is that any methods described in the prototype are not considered as headers\r\n\r\n### Current Behavior\r\nthe call fails with the following stack trace:\r\n```\r\nTypeError: The header content contains invalid characters\r\n    at ClientRequest.setHeader (_http_outgoing.js:374:11)\r\n    at new ClientRequest (_http_client.js:131:14)\r\n    at Object.request (http.js:26:10)\r\n    at Request.start (/Users/ekkis/dev/node_modules/request/request.js:748:32)\r\n    at Request.write (/Users/ekkis/dev/node_modules/request/request.js:1466:10)\r\n    at FormData.ondata (internal/streams/legacy.js:16:26)\r\n    at emitOne (events.js:96:13)\r\n    at FormData.emit (events.js:191:7)\r\n    at FormData.CombinedStream.write (/Users/ekkis/dev/node_modules/combined-stream/lib/combined_stream.js:118:8)\r\n    at FormData.CombinedStream._pipeNext (/Users/ekkis/dev/node_modules/combined-stream/lib/combined_stream.js:106:8)\r\n```\r\n\r\n### Possible Solution\r\nI'm guessing somewhere the code is doing a `for (k in o)` when it should be doing something like `Object.keys(o).forEach(function(k) {})` and that needs fixing\r\n\r\n### Context\r\nI'm unable to post a form to a listening server.  I believe it may be related to this issue https://github.com/request/request/issues/2367 but different in its genesis\r\n\r\n### Your Environment\r\n\r\n| software         | version\r\n| ---------------- | -------\r\n| request          | 2.27.0\r\n| node             | 7.7.2\r\n| npm              | 4.1.2\r\n| Operating System | OSX 10.11.6"},"comment":{"url":"https://api.github.com/repos/request/request/issues/comments/373898402","html_url":"https://github.com/request/request/issues/2632#issuecomment-373898402","issue_url":"https://api.github.com/repos/request/request/issues/2632","id":373898402,"user":{"login":"pnlinh-it","id":11713395,"avatar_url":"https://avatars3.githubusercontent.com/u/11713395?v=4","gravatar_id":"","url":"https://api.github.com/users/pnlinh-it","html_url":"https://github.com/pnlinh-it","followers_url":"https://api.github.com/users/pnlinh-it/followers","following_url":"https://api.github.com/users/pnlinh-it/following{/other_user}","gists_url":"https://api.github.com/users/pnlinh-it/gists{/gist_id}","starred_url":"https://api.github.com/users/pnlinh-it/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pnlinh-it/subscriptions","organizations_url":"https://api.github.com/users/pnlinh-it/orgs","repos_url":"https://api.github.com/users/pnlinh-it/repos","events_url":"https://api.github.com/users/pnlinh-it/events{/privacy}","received_events_url":"https://api.github.com/users/pnlinh-it/received_events","type":"User","site_admin":false},"created_at":"2018-03-17T06:32:13Z","updated_at":"2018-03-17T06:32:13Z","author_association":"NONE","body":"@ekkis Work like a charm"}}
{"actor":{"display_login":"pnlinh-it"}}