Skip to content

Commit 34dcdf3

Browse files
committed
writeblob
1 parent dc6e0b3 commit 34dcdf3

File tree

2 files changed

+34
-43
lines changed

2 files changed

+34
-43
lines changed

lib/dispatcher/client-h1.js

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1369,33 +1369,29 @@ function writeBuffer (abort, body, client, request, socket, contentLength, heade
13691369
function writeBlob (abort, body, client, request, socket, contentLength, header, expectsPayload) {
13701370
assert(contentLength === body.size, 'blob body must have content length')
13711371

1372-
try {
1373-
if (contentLength != null && contentLength !== body.size) {
1374-
throw new RequestContentLengthMismatchError()
1375-
}
1376-
1377-
body.arrayBuffer().then(arrayBuffer => {
1378-
const buffer = Buffer.from(arrayBuffer)
1372+
if (contentLength != null && contentLength !== body.size) {
1373+
abort(new RequestContentLengthMismatchError())
1374+
return
1375+
}
1376+
body.arrayBuffer().then(arrayBuffer => {
1377+
const buffer = Buffer.from(arrayBuffer)
13791378

1380-
socket.cork()
1381-
socket.write(`${header}content-length: ${contentLength}\r\n\r\n`, 'latin1')
1382-
socket.write(buffer)
1383-
socket.uncork()
1379+
socket.cork()
1380+
socket.write(`${header}content-length: ${contentLength}\r\n\r\n`, 'latin1')
1381+
socket.write(buffer)
1382+
socket.uncork()
13841383

1385-
request.onBodySent(buffer)
1386-
request.onRequestSent()
1384+
request.onBodySent(buffer)
1385+
request.onRequestSent()
13871386

1388-
if (!expectsPayload && request.reset !== false) {
1389-
socket[kReset] = true
1390-
}
1387+
if (!expectsPayload && request.reset !== false) {
1388+
socket[kReset] = true
1389+
}
13911390

1392-
client[kResume]()
1393-
}).catch(err => {
1394-
abort(err)
1395-
})
1396-
} catch (err) {
1391+
client[kResume]()
1392+
}).catch(err => {
13971393
abort(err)
1398-
}
1394+
})
13991395
}
14001396

14011397
/**

lib/dispatcher/client-h2.js

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -732,31 +732,26 @@ function writeStream (abort, socket, expectsPayload, h2stream, body, client, req
732732
function writeBlob (abort, h2stream, body, client, request, socket, contentLength, expectsPayload) {
733733
assert(contentLength === body.size, 'blob body must have content length')
734734

735-
try {
736-
if (contentLength != null && contentLength !== body.size) {
737-
throw new RequestContentLengthMismatchError()
738-
}
739-
740-
body.arrayBuffer().then(arrayBuffer => {
741-
const buffer = Buffer.from(arrayBuffer)
735+
if (contentLength != null && contentLength !== body.size) {
736+
abort(new RequestContentLengthMismatchError())
737+
}
738+
body.arrayBuffer().then(arrayBuffer => {
739+
const buffer = Buffer.from(arrayBuffer)
742740

743-
h2stream.cork()
744-
h2stream.write(buffer)
745-
h2stream.uncork()
746-
h2stream.end()
741+
h2stream.cork()
742+
h2stream.write(buffer)
743+
h2stream.uncork()
744+
h2stream.end()
747745

748-
request.onBodySent(buffer)
749-
request.onRequestSent()
746+
request.onBodySent(buffer)
747+
request.onRequestSent()
750748

751-
if (!expectsPayload) {
752-
socket[kReset] = true
753-
}
749+
if (!expectsPayload) {
750+
socket[kReset] = true
751+
}
754752

755-
client[kResume]()
756-
}).catch(err => abort(err))
757-
} catch (err) {
758-
abort(err)
759-
}
753+
client[kResume]()
754+
}).catch(err => abort(err))
760755
}
761756

762757
async function writeIterable (abort, h2stream, body, client, request, socket, contentLength, expectsPayload) {

0 commit comments

Comments
 (0)