@@ -29,6 +29,7 @@ const {
2929 NGHTTP2_NO_ERROR ,
3030} = internalBinding ( 'http2' ) . constants ;
3131const EventEmitter = require ( 'events' ) ;
32+ const { Buffer } = require ( 'buffer' ) ;
3233
3334const kRequestUrl = Symbol ( 'kRequestUrl' ) ;
3435
@@ -126,13 +127,40 @@ function onClientStreamError({ stream, error }) {
126127/**
127128 * When a chunk of the request body is being sent, cache it until `getRequestPostData` request.
128129 * https://chromedevtools.github.io/devtools-protocol/1-3/Network/#method-getRequestPostData
129- * @param {{ stream: import('http2').ClientHttp2Stream, chunk: Buffer } } event
130+ * @param {{
131+ * stream: import('http2').ClientHttp2Stream,
132+ * writev: boolean,
133+ * data: Buffer | string | Array<Buffer | {chunk: Buffer|string, encoding: string}>,
134+ * encoding: string,
135+ * }} event
130136 */
131- function onClientStreamBodyChunkSent ( { stream, chunk } ) {
137+ function onClientStreamBodyChunkSent ( { stream, writev , data , encoding } ) {
132138 if ( typeof stream [ kInspectorRequestId ] !== 'string' ) {
133139 return ;
134140 }
135141
142+ let chunk ;
143+
144+ if ( writev ) {
145+ if ( data . allBuffers ) {
146+ chunk = Buffer . concat ( data ) ;
147+ } else {
148+ const buffers = [ ] ;
149+ for ( let i = 0 ; i < data . length ; ++ i ) {
150+ if ( typeof data [ i ] . chunk === 'string' ) {
151+ buffers . push ( Buffer . from ( data [ i ] . chunk , data [ i ] . encoding ) ) ;
152+ } else {
153+ buffers . push ( data [ i ] . chunk ) ;
154+ }
155+ }
156+ chunk = Buffer . concat ( buffers ) ;
157+ }
158+ } else if ( typeof data === 'string' ) {
159+ chunk = Buffer . from ( data , encoding ) ;
160+ } else {
161+ chunk = data ;
162+ }
163+
136164 Network . dataSent ( {
137165 requestId : stream [ kInspectorRequestId ] ,
138166 timestamp : getMonotonicTime ( ) ,
0 commit comments