| 81 | } |
| 82 | |
| 83 | constructor({ method }) { |
| 84 | super({ method }); |
| 85 | |
| 86 | this[BODY] = []; |
| 87 | this[HEADERS] = {}; |
| 88 | |
| 89 | this.useChunkedEncodingByDefault = false; |
| 90 | this.chunkedEncoding = false; |
| 91 | this._header = ''; |
| 92 | |
| 93 | this.assignSocket({ |
| 94 | _writableState: {}, |
| 95 | writable: true, |
| 96 | on: Function.prototype, |
| 97 | removeListener: Function.prototype, |
| 98 | destroy: Function.prototype, |
| 99 | cork: Function.prototype, |
| 100 | uncork: Function.prototype, |
| 101 | write: (data, encoding, cb) => { |
| 102 | if (typeof encoding === 'function') { |
| 103 | cb = encoding; |
| 104 | encoding = null; |
| 105 | } |
| 106 | |
| 107 | if (this._header === '' || this._wroteHeader) { |
| 108 | addData(this, data); |
| 109 | } else { |
| 110 | const string = getString(data); |
| 111 | const index = string.indexOf(headerEnd); |
| 112 | |
| 113 | if (index !== -1) { |
| 114 | const remainder = string.slice(index + headerEnd.length); |
| 115 | |
| 116 | if (remainder) { |
| 117 | addData(this, remainder); |
| 118 | } |
| 119 | |
| 120 | this._wroteHeader = true; |
| 121 | } |
| 122 | } |
| 123 | |
| 124 | if (typeof cb === 'function') { |
| 125 | cb(); |
| 126 | } |
| 127 | return true; |
| 128 | }, |
| 129 | }); |
| 130 | } |
| 131 | |
| 132 | }; |