Skip to content

Commit df6d3ce

Browse files
committed
Use curl's --compressed option for requests that accept it
1 parent 7fd160c commit df6d3ce

File tree

3 files changed

+23
-0
lines changed

3 files changed

+23
-0
lines changed

src/targets/shell/curl.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ module.exports = function (source, options) {
4040
code.push(opts.short ? '-0' : '--http1.0')
4141
}
4242

43+
if (headerHelpers.getHeader(source.allHeaders, 'accept-encoding')) {
44+
code.push('--compressed')
45+
}
46+
4347
// if multipart form data, we want to remove the boundary
4448
if (source.postData.mimeType === 'multipart/form-data') {
4549
const contentTypeHeaderName = headerHelpers.getHeaderName(source.headersObj, 'content-type')
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"method": "GET",
3+
"url": "http://mockbin.com/har",
4+
"headers": [
5+
{
6+
"name": "accept-encoding",
7+
"value": "deflate, gzip, br"
8+
}
9+
]
10+
}

test/targets/shell/curl.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,15 @@ module.exports = function (HTTPSnippet, fixtures) {
6464
result.should.eql('curl --request GET --url http://mockbin.com/request --http1.0')
6565
})
6666

67+
it('should use --compressed for requests that accept encodings', function () {
68+
const result = new HTTPSnippet(fixtures.curl.compression).convert('shell', 'curl', {
69+
indent: false
70+
})
71+
72+
result.should.be.a.String()
73+
result.should.eql("curl --request GET --url http://mockbin.com/har --compressed --header 'accept-encoding: deflate, gzip, br'")
74+
})
75+
6776
it('should use custom indentation', function () {
6877
const result = new HTTPSnippet(fixtures.requests.full).convert('shell', 'curl', {
6978
indent: '@'

0 commit comments

Comments
 (0)