From 0dc184938ce8b17ded69b03ebbe34b5345816a7b Mon Sep 17 00:00:00 2001 From: Eric Avdey Date: Wed, 29 Apr 2015 15:56:53 -0300 Subject: [PATCH] Remove the octets numbers from the chunked response for blueprint output Chunked transfer encoding format includes the number of the octets of the data in each chunk as a part of the response. This commit adds detection of the `Transfer-Encoding: chunked` into the parser to strip the numbers from the output for blueprint format. The output of raw format kept not modified. This fix probably also resolves issue apiaryio/curl-trace-parser#6. --- bin/curl-trace-parser | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/bin/curl-trace-parser b/bin/curl-trace-parser index d18e1a3..647345b 100755 --- a/bin/curl-trace-parser +++ b/bin/curl-trace-parser @@ -31,6 +31,11 @@ process.stdin.on('end', function() { } if(option == 'b' || option == '--blueprint'){ var rawPair = curl.parse(stdin); + var response = rawPair['response']; + if (/transfer-encoding:\s*?chunked/gi.test(response)) { + var hexPattern = /\r\n[0-9a-f]{1,2}\r\n/gi; + rawPair['response'] = response.replace(hexPattern, '\r\n'); + } parsedPair = { 'request': http.parseRequest(rawPair['request']), 'response': http.parseResponse(rawPair['response'])