curl command a gzipped POST body to an apache server

前端 未结 2 1992
星月不相逢
星月不相逢 2021-01-02 08:40

With mod_deflate properly activated on my apache 2.2 server, I am trying to send a gzipped body via curl command line.

All tutorials I have seen say to add -H\'Conte

相关标签:
2条回答
  • 2021-01-02 09:13

    Single line:

    echo '{"mydummy": "json"}' | gzip | curl -v -i --data-binary @- -H "Content-Encoding: gzip" http://localhost/mymodule
    
    0 讨论(0)
  • 2021-01-02 09:17

    The thing is that mod_deflate does not like the gzip header shown here:

    hexdump -C body.gz
    00000000  1f 8b 08 08 20 08 30 59  00 03 62 6f 64 79 00 ab  |.... .0Y..body..|
    00000010  56 50 ca ad 4c 29 cd cd  ad 54 52 b0 52 50 ca 2a  |VP..L)...TR.RP.*|
    00000020  ce cf 53 52 a8 e5 02 00  a6 6a 24 99 17 00 00 00  |..SR.....j$.....|
    00000030
    

    The solution is simply to give it to gzip without the intermediate file step, if taking a stream, it will not print the headers and apache will like the body!

    echo '{ "mydummy" : "json" }' | gzip > body.gz
    curl -v -i http://localhost/mymodule -H'Content-Encoding: gzip' --data-binary @body.gz
    

    This works, the apache module receives the decompressed bytes.

    You can see the header difference here, you no longer see the file name (body) in the gzip file:

    hexdump -C body.gz
    00000000  1f 8b 08 00 08 0a 30 59  00 03 ab 56 50 ca ad 4c  |......0Y...VP..L|
    00000010  29 cd cd ad 54 52 b0 52  50 ca 2a ce cf 53 52 a8  |)...TR.RP.*..SR.|
    00000020  e5 02 00 a6 6a 24 99 17  00 00 00                 |....j$.....|
    0000002b
    
    0 讨论(0)
提交回复
热议问题