File tree Expand file tree Collapse file tree 2 files changed +20
-2
lines changed Expand file tree Collapse file tree 2 files changed +20
-2
lines changed Original file line number Diff line number Diff line change @@ -7,6 +7,7 @@ const express = require('express')
77const concat = require ( 'concat-stream' ) ;
88const { promisify } = require ( 'util' ) ;
99const promBundle = require ( "express-prom-bundle" ) ;
10+ const zlib = require ( "zlib" ) ;
1011
1112const {
1213 PROMETHEUS_ENABLED = false ,
@@ -40,11 +41,16 @@ if(process.env.DISABLE_REQUEST_LOGS !== 'true'){
4041
4142app . use ( function ( req , res , next ) {
4243 req . pipe ( concat ( function ( data ) {
43- req . body = data . toString ( 'utf8' ) ;
44+
45+ if ( req . get ( "Content-Encoding" ) === "gzip" ) {
46+ req . body = zlib . gunzipSync ( data ) . toString ( 'utf8' ) ;
47+ }
48+ else {
49+ req . body = data . toString ( 'utf8' ) ;
50+ }
4451 next ( ) ;
4552 } ) ) ;
4653} ) ;
47-
4854//Handle all paths
4955app . all ( '*' , ( req , res ) => {
5056
Original file line number Diff line number Diff line change @@ -155,6 +155,18 @@ else
155155 exit 1
156156fi
157157
158+
159+ message " Make JSON request with gzip Content-Encoding, and test that json is in the output. "
160+ REQUEST=$( echo -n ' {"a":"b"}' | gzip | curl -s -X POST -H " Content-Encoding: gzip" -H " Content-Type: application/json" --data-binary @- http://localhost:8080/)
161+ if [ $( echo $REQUEST | jq -r ' .json.a' ) == ' b' ]
162+ then
163+ passed " JSON test passed."
164+ else
165+ failed " JSON test failed."
166+ echo $REQUEST | jq
167+ exit 1
168+ fi
169+
158170REQUEST=$( curl -s -X POST -H " Content-Type: application/json" -d ' not-json' http://localhost:8080)
159171if [ $( echo $REQUEST | jq -r ' .json' ) == ' null' ]; then
160172 passed " JSON with Invalid Body test passed."
You can’t perform that action at this time.
0 commit comments