File tree 2 files changed +20
-2
lines changed
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')
7
7
const concat = require ( 'concat-stream' ) ;
8
8
const { promisify } = require ( 'util' ) ;
9
9
const promBundle = require ( "express-prom-bundle" ) ;
10
+ const zlib = require ( "zlib" ) ;
10
11
11
12
const {
12
13
PROMETHEUS_ENABLED = false ,
@@ -40,11 +41,16 @@ if(process.env.DISABLE_REQUEST_LOGS !== 'true'){
40
41
41
42
app . use ( function ( req , res , next ) {
42
43
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
+ }
44
51
next ( ) ;
45
52
} ) ) ;
46
53
} ) ;
47
-
48
54
//Handle all paths
49
55
app . all ( '*' , ( req , res ) => {
50
56
Original file line number Diff line number Diff line change @@ -155,6 +155,18 @@ else
155
155
exit 1
156
156
fi
157
157
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
+
158
170
REQUEST=$( curl -s -X POST -H " Content-Type: application/json" -d ' not-json' http://localhost:8080)
159
171
if [ $( echo $REQUEST | jq -r ' .json' ) == ' null' ]; then
160
172
passed " JSON with Invalid Body test passed."
You can’t perform that action at this time.
0 commit comments