2017-09-19 27 views
5

私はSpringブートRESTアプリケーション(1.5.6.RELEASE)を持っています。 gzip圧縮を着信と発信したいと思います。このドキュメントhttps://docs.spring.io/spring-boot/docs/current/reference/html/common-application-properties.htmlあたりとして、私はSpringブートRESTアプリケーションでのgzipped要求の処理

server.compression.enabled=true 
server.compression.mime-types=... 

を設定している。しかし、これは私だけのサービスからgzipping応答には適用されているようだ(これはドキュメントが実際に言っていることである「応答圧縮が有効になっている場合は#。」)。

私の問題は、着信gzipped要求が圧縮解除されていないため、JSON構文解析エラーが発生することです。

誰かが私のSpring Bootアプリケーションでリクエストの解凍をどのように有効にすることができるか知っていますか?

EDIT例:

POMスニペット:

<parent> 
    <groupId>org.springframework.boot</groupId> 
    <artifactId>spring-boot-starter-parent</artifactId> 
    <version>1.5.6.RELEASE</version> 
</parent> 
<dependencies> 
    <dependency> 
     <groupId>org.springframework.boot</groupId> 
     <artifactId>spring-boot-starter-web</artifactId> 
    </dependency> 
</dependencies> 

コントローラコード:

@RestController 
public class Controller { 
    @RequestMapping(value = "/", method = RequestMethod.POST, consumes = "application/json") 
    public String post(@RequestBody Map<String, String> request) { 
     return request.get("key"); 
    } 
} 

カールを使用した試験:

$ echo '{ "key":"hello" }' > body 
$ curl -X POST -H "Content-Type: application/json" --data-binary @body http://localhost:8080 # prints 'hello' 
$ echo '{ "key":"hello" }' | gzip > body.gz 
$ curl -X POST -H "Content-Type: application/json" -H "Content-Encoding: gzip" --data-binary @body.gz http://localhost:8080 # fails 

gzipで圧縮された呼び出しがメッセージで失敗します。

{"timestamp":1505843443456,"status":400,"error":"Bad Request","exception":"org.springframework.http.converter.HttpMessageNotReadableException","message":"JSON parse error: Illegal character ((CTRL-CHAR, code 31)): only regular white space (\\r, \\n, \\t) is allowed between tokens; nested exception is com.fasterxml.jackson.core.JsonParseException: Illegal character ((CTRL-CHAR, code 31)): only regular white space (\\r, \\n, \\t) is allowed between tokens\n at [Source: [email protected]; line: 1, column: 2]","path":"/"} 
+0

どのように圧縮要求を発行しますか? – diginoise

+0

https://stackoverflow.com/q/20507007/46673、https://stackoverflow.com/q/16638345/466738、https://serverfault.com/questions/56700/is-it-possible-to- enable-http-compression-for-requests –

+0

@diginoise私はクライアントを制御しません – B255

答えて

0

server.compression.*設定キーのみHTTP応答圧縮についてです。私は、一般的な解決策や、サーバーがそれをネイティブにサポートしているかどうかはわかりません。

これをサポートするサーブレットフィルタを使用してサポートすることはできますが、Springブートはその機能を提供しません。

+0

、またはApacheの背後にサーブレットコンテナを置き、Apacheがそれを処理するようにします:https://serverfault.com/questions/(HTTPヘッダと本文)は何ですか? 56700/is-it-possible-possible-to-enable-http-compression-for-requests#answer-56707 – Adam

+0

または、nginxを使用するかcdnを使用してください... –

+0

よく、私はnginxがそうしているかどうか - https://serverfault.com/questions/334215/how-do-i-configure-nginx-to-accept-gzip-requests - 2011年から。しかし、最近nginxがリクエストを許可すると言った最近のものは見つかりませんでした圧縮(nginxのドキュメントを介して 'content-encoding'で検索) – Adam

関連する問題