| 102 | } |
| 103 | |
| 104 | function done() { |
| 105 | bodyWriter.end(); |
| 106 | |
| 107 | if (unsupportedContentEncoding) { |
| 108 | next( |
| 109 | new UnsupportedMediaTypeError( |
| 110 | { |
| 111 | info: { |
| 112 | contentEncoding: unsupportedContentEncoding |
| 113 | } |
| 114 | }, |
| 115 | 'content encoding not supported' |
| 116 | ) |
| 117 | ); |
| 118 | return; |
| 119 | } |
| 120 | |
| 121 | if (maxBodySize && bytesReceived > maxBodySize) { |
| 122 | var msg = 'Request body size exceeds ' + maxBodySize; |
| 123 | var err; |
| 124 | |
| 125 | // Between Node 0.12 and 4 http status code messages changed |
| 126 | // RequestEntityTooLarge was changed to PayloadTooLarge |
| 127 | // this check is to maintain backwards compatibility |
| 128 | if (PayloadTooLargeError !== undefined) { |
| 129 | err = new PayloadTooLargeError(msg); |
| 130 | } else { |
| 131 | err = new RequestEntityTooLargeError(msg); |
| 132 | } |
| 133 | |
| 134 | next(err); |
| 135 | return; |
| 136 | } |
| 137 | |
| 138 | if (!req.body.length) { |
| 139 | next(); |
| 140 | return; |
| 141 | } |
| 142 | |
| 143 | if (hash && md5 !== (digest = hash.digest('base64'))) { |
| 144 | next(new BadDigestError(MD5_MSG, md5, digest)); |
| 145 | return; |
| 146 | } |
| 147 | |
| 148 | next(); |
| 149 | } |
| 150 | |
| 151 | if (req.headers['content-encoding'] === undefined) { |
| 152 | // This handles the original else branch |