Last active
December 29, 2015 19:09
-
-
Save erichocean/7715450 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| http.createServer(function (req, res) { | |
| req.setEncoding('binary'); // THE FIX IS TO COMMENT OUT THIS LINE. Then you'll get buffers. | |
| req.content = Buffer.concat([]); | |
| console.log(req); // I verified Content-Type is "application/octet-stream", see below for full console output. | |
| req.addListener("data", function(chunk) { | |
| console.log(typeof chunk); // Get "string", want "object". | |
| console.log(chunk); // Want <Buffer: 0x...>, get a string instead. | |
| console.log(req.content); // Prints <Buffer > as expected. | |
| req.content = Buffer.concat([req.content, chunk]); // Fails in buffer.js:499 -- buf.copy(buffer, pos); | |
| }); | |
| req.addListener("end", function() {}); | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { _readableState: | |
| { highWaterMark: 16384, | |
| buffer: [], | |
| length: 0, | |
| pipes: null, | |
| pipesCount: 0, | |
| flowing: false, | |
| ended: false, | |
| endEmitted: false, | |
| reading: false, | |
| calledRead: false, | |
| sync: true, | |
| needReadable: false, | |
| emittedReadable: false, | |
| readableListening: false, | |
| objectMode: false, | |
| defaultEncoding: 'utf8', | |
| ranOut: false, | |
| awaitDrain: 0, | |
| readingMore: false, | |
| decoder: { encoding: 'binary', write: [Function: passThroughWrite] }, | |
| encoding: 'binary' }, | |
| readable: true, | |
| domain: null, | |
| _events: {}, | |
| _maxListeners: 10, | |
| socket: | |
| { _connecting: false, | |
| _handle: | |
| { fd: 15, | |
| writeQueueSize: 0, | |
| owner: [Circular], | |
| onread: [Function: onread], | |
| reading: true }, | |
| _readableState: | |
| { highWaterMark: 16384, | |
| buffer: [], | |
| length: 0, | |
| pipes: null, | |
| pipesCount: 0, | |
| flowing: false, | |
| ended: false, | |
| endEmitted: false, | |
| reading: true, | |
| calledRead: true, | |
| sync: false, | |
| needReadable: true, | |
| emittedReadable: false, | |
| readableListening: false, | |
| objectMode: false, | |
| defaultEncoding: 'utf8', | |
| ranOut: false, | |
| awaitDrain: 0, | |
| readingMore: false, | |
| decoder: null, | |
| encoding: null }, | |
| readable: true, | |
| domain: null, | |
| _events: | |
| { end: [Object], | |
| finish: [Function: onSocketFinish], | |
| _socketEnd: [Function: onSocketEnd], | |
| drain: [Function: ondrain], | |
| timeout: [Function], | |
| error: [Function], | |
| close: [Object] }, | |
| _maxListeners: 10, | |
| _writableState: | |
| { highWaterMark: 16384, | |
| objectMode: false, | |
| needDrain: false, | |
| ending: false, | |
| ended: false, | |
| finished: false, | |
| decodeStrings: false, | |
| defaultEncoding: 'utf8', | |
| length: 0, | |
| writing: false, | |
| sync: true, | |
| bufferProcessing: false, | |
| onwrite: [Function], | |
| writecb: null, | |
| writelen: 0, | |
| buffer: [] }, | |
| writable: true, | |
| allowHalfOpen: true, | |
| onend: [Function], | |
| destroyed: false, | |
| errorEmitted: false, | |
| bytesRead: 444, | |
| _bytesDispatched: 0, | |
| _pendingData: null, | |
| _pendingEncoding: '', | |
| server: | |
| { domain: null, | |
| _events: [Object], | |
| _maxListeners: 10, | |
| _connections: 1, | |
| connections: [Getter/Setter], | |
| _handle: [Object], | |
| _usingSlaves: false, | |
| _slaves: [], | |
| allowHalfOpen: true, | |
| httpAllowHalfOpen: false, | |
| timeout: 120000, | |
| _connectionKey: '4:127.0.0.1:3001' }, | |
| _idleTimeout: 120000, | |
| _idleNext: { _idleNext: [Circular], _idlePrev: [Circular] }, | |
| _idlePrev: { _idleNext: [Circular], _idlePrev: [Circular] }, | |
| _idleStart: 1385786034736, | |
| parser: | |
| { _headers: [], | |
| _url: '', | |
| onHeaders: [Function: parserOnHeaders], | |
| onHeadersComplete: [Function: parserOnHeadersComplete], | |
| onBody: [Function: parserOnBody], | |
| onMessageComplete: [Function: parserOnMessageComplete], | |
| socket: [Circular], | |
| incoming: [Circular], | |
| maxHeaderPairs: 2000, | |
| onIncoming: [Function] }, | |
| ondata: [Function], | |
| _httpMessage: | |
| { domain: null, | |
| _events: [Object], | |
| _maxListeners: 10, | |
| output: [], | |
| outputEncodings: [], | |
| writable: true, | |
| _last: false, | |
| chunkedEncoding: false, | |
| shouldKeepAlive: true, | |
| useChunkedEncodingByDefault: true, | |
| sendDate: true, | |
| _hasBody: true, | |
| _trailer: '', | |
| finished: false, | |
| _hangupClose: false, | |
| socket: [Circular], | |
| connection: [Circular] } }, | |
| connection: | |
| { _connecting: false, | |
| _handle: | |
| { fd: 15, | |
| writeQueueSize: 0, | |
| owner: [Circular], | |
| onread: [Function: onread], | |
| reading: true }, | |
| _readableState: | |
| { highWaterMark: 16384, | |
| buffer: [], | |
| length: 0, | |
| pipes: null, | |
| pipesCount: 0, | |
| flowing: false, | |
| ended: false, | |
| endEmitted: false, | |
| reading: true, | |
| calledRead: true, | |
| sync: false, | |
| needReadable: true, | |
| emittedReadable: false, | |
| readableListening: false, | |
| objectMode: false, | |
| defaultEncoding: 'utf8', | |
| ranOut: false, | |
| awaitDrain: 0, | |
| readingMore: false, | |
| decoder: null, | |
| encoding: null }, | |
| readable: true, | |
| domain: null, | |
| _events: | |
| { end: [Object], | |
| finish: [Function: onSocketFinish], | |
| _socketEnd: [Function: onSocketEnd], | |
| drain: [Function: ondrain], | |
| timeout: [Function], | |
| error: [Function], | |
| close: [Object] }, | |
| _maxListeners: 10, | |
| _writableState: | |
| { highWaterMark: 16384, | |
| objectMode: false, | |
| needDrain: false, | |
| ending: false, | |
| ended: false, | |
| finished: false, | |
| decodeStrings: false, | |
| defaultEncoding: 'utf8', | |
| length: 0, | |
| writing: false, | |
| sync: true, | |
| bufferProcessing: false, | |
| onwrite: [Function], | |
| writecb: null, | |
| writelen: 0, | |
| buffer: [] }, | |
| writable: true, | |
| allowHalfOpen: true, | |
| onend: [Function], | |
| destroyed: false, | |
| errorEmitted: false, | |
| bytesRead: 444, | |
| _bytesDispatched: 0, | |
| _pendingData: null, | |
| _pendingEncoding: '', | |
| server: | |
| { domain: null, | |
| _events: [Object], | |
| _maxListeners: 10, | |
| _connections: 1, | |
| connections: [Getter/Setter], | |
| _handle: [Object], | |
| _usingSlaves: false, | |
| _slaves: [], | |
| allowHalfOpen: true, | |
| httpAllowHalfOpen: false, | |
| timeout: 120000, | |
| _connectionKey: '4:127.0.0.1:3001' }, | |
| _idleTimeout: 120000, | |
| _idleNext: { _idleNext: [Circular], _idlePrev: [Circular] }, | |
| _idlePrev: { _idleNext: [Circular], _idlePrev: [Circular] }, | |
| _idleStart: 1385786034736, | |
| parser: | |
| { _headers: [], | |
| _url: '', | |
| onHeaders: [Function: parserOnHeaders], | |
| onHeadersComplete: [Function: parserOnHeadersComplete], | |
| onBody: [Function: parserOnBody], | |
| onMessageComplete: [Function: parserOnMessageComplete], | |
| socket: [Circular], | |
| incoming: [Circular], | |
| maxHeaderPairs: 2000, | |
| onIncoming: [Function] }, | |
| ondata: [Function], | |
| _httpMessage: | |
| { domain: null, | |
| _events: [Object], | |
| _maxListeners: 10, | |
| output: [], | |
| outputEncodings: [], | |
| writable: true, | |
| _last: false, | |
| chunkedEncoding: false, | |
| shouldKeepAlive: true, | |
| useChunkedEncodingByDefault: true, | |
| sendDate: true, | |
| _hasBody: true, | |
| _trailer: '', | |
| finished: false, | |
| _hangupClose: false, | |
| socket: [Circular], | |
| connection: [Circular] } }, | |
| httpVersion: '1.1', | |
| complete: false, | |
| headers: | |
| { host: 'localhost:3001', | |
| 'accept-encoding': 'gzip, deflate', | |
| 'content-type': 'application/octet-stream', | |
| 'content-length': '184', | |
| 'accept-language': 'en-us', | |
| accept: '*/*', | |
| connection: 'keep-alive', | |
| 'user-agent': 'RollRandom/1.35 CFNetwork/672.0.2 Darwin/12.5.0' }, | |
| trailers: {}, | |
| _pendings: [], | |
| _pendingIndex: 0, | |
| url: '/post', | |
| method: 'POST', | |
| statusCode: null, | |
| client: | |
| { _connecting: false, | |
| _handle: | |
| { fd: 15, | |
| writeQueueSize: 0, | |
| owner: [Circular], | |
| onread: [Function: onread], | |
| reading: true }, | |
| _readableState: | |
| { highWaterMark: 16384, | |
| buffer: [], | |
| length: 0, | |
| pipes: null, | |
| pipesCount: 0, | |
| flowing: false, | |
| ended: false, | |
| endEmitted: false, | |
| reading: true, | |
| calledRead: true, | |
| sync: false, | |
| needReadable: true, | |
| emittedReadable: false, | |
| readableListening: false, | |
| objectMode: false, | |
| defaultEncoding: 'utf8', | |
| ranOut: false, | |
| awaitDrain: 0, | |
| readingMore: false, | |
| decoder: null, | |
| encoding: null }, | |
| readable: true, | |
| domain: null, | |
| _events: | |
| { end: [Object], | |
| finish: [Function: onSocketFinish], | |
| _socketEnd: [Function: onSocketEnd], | |
| drain: [Function: ondrain], | |
| timeout: [Function], | |
| error: [Function], | |
| close: [Object] }, | |
| _maxListeners: 10, | |
| _writableState: | |
| { highWaterMark: 16384, | |
| objectMode: false, | |
| needDrain: false, | |
| ending: false, | |
| ended: false, | |
| finished: false, | |
| decodeStrings: false, | |
| defaultEncoding: 'utf8', | |
| length: 0, | |
| writing: false, | |
| sync: true, | |
| bufferProcessing: false, | |
| onwrite: [Function], | |
| writecb: null, | |
| writelen: 0, | |
| buffer: [] }, | |
| writable: true, | |
| allowHalfOpen: true, | |
| onend: [Function], | |
| destroyed: false, | |
| errorEmitted: false, | |
| bytesRead: 444, | |
| _bytesDispatched: 0, | |
| _pendingData: null, | |
| _pendingEncoding: '', | |
| server: | |
| { domain: null, | |
| _events: [Object], | |
| _maxListeners: 10, | |
| _connections: 1, | |
| connections: [Getter/Setter], | |
| _handle: [Object], | |
| _usingSlaves: false, | |
| _slaves: [], | |
| allowHalfOpen: true, | |
| httpAllowHalfOpen: false, | |
| timeout: 120000, | |
| _connectionKey: '4:127.0.0.1:3001' }, | |
| _idleTimeout: 120000, | |
| _idleNext: { _idleNext: [Circular], _idlePrev: [Circular] }, | |
| _idlePrev: { _idleNext: [Circular], _idlePrev: [Circular] }, | |
| _idleStart: 1385786034736, | |
| parser: | |
| { _headers: [], | |
| _url: '', | |
| onHeaders: [Function: parserOnHeaders], | |
| onHeadersComplete: [Function: parserOnHeadersComplete], | |
| onBody: [Function: parserOnBody], | |
| onMessageComplete: [Function: parserOnMessageComplete], | |
| socket: [Circular], | |
| incoming: [Circular], | |
| maxHeaderPairs: 2000, | |
| onIncoming: [Function] }, | |
| ondata: [Function], | |
| _httpMessage: | |
| { domain: null, | |
| _events: [Object], | |
| _maxListeners: 10, | |
| output: [], | |
| outputEncodings: [], | |
| writable: true, | |
| _last: false, | |
| chunkedEncoding: false, | |
| shouldKeepAlive: true, | |
| useChunkedEncodingByDefault: true, | |
| sendDate: true, | |
| _hasBody: true, | |
| _trailer: '', | |
| finished: false, | |
| _hangupClose: false, | |
| socket: [Circular], | |
| connection: [Circular] } }, | |
| _consuming: false, | |
| _dumped: false, | |
| httpVersionMajor: 1, | |
| httpVersionMinor: 1, | |
| upgrade: false, | |
| content: <Buffer > } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment