ããã«ã¡ã¯ã ã¨ããµã¤ãæ ªå¼ä¼ç¤¾ã®ä¸æµ¦ã§ãã
APIãªã©ããã®ã¬ã¹ãã³ã¹ã¯ããµã¤ãºãå°ããã«è¶ãããã¨ã¯ããã¾ããã
ã¬ã¹ãã³ã¹ãµã¤ãºãå°ããããæ¹æ³ã®1ã¤ã«ãã¬ã¹ãã³ã¹ãgzipã§å§ç¸®ããã¨ããæ¹æ³ãããã¾ãã APIå´ã§ã¬ã¹ãã³ã¹ãgzipå§ç¸®ãã¦éä¿¡ããåãåãå´ã§è§£åãã¦ä½¿ç¨ããã¨ããããæ¹ã§ãã
ã§ãããå®ã¯Javaã®RestTemplateã¯ãããã©ã«ãã§ã¯gzipå§ç¸®ããã¬ã¹ãã³ã¹ã使ããã¨ãã§ãã¾ããã
ããã§ã¯ãRestTemplateã使ã£ã¦gzipå§ç¸®ãããã¬ã¹ãã³ã¹ã使ç¨ã§ããããã«ããæ¹æ³ã説æãã¾ãã
ã¬ã¹ãã³ã¹ã®ãµã¤ãº
APIãªã©ããåãåãã¬ã¹ãã³ã¹ã®ãµã¤ãºã¯ãå°ããã«è¶ãããã¨ã¯ããã¾ããã å°ããã¨ã
- ã¬ã¹ãã³ã¹å ¨ä½ã®è»¢éå®äºã¾ã§ã®é度ãä¸ãã
- 転ééãæ¸ãã®ã§ã転ééãã¨ã«æéããããå ´åãæéãåæ¸ãããã¨ãã§ãã
ãªã©ã®å©ç¹ãããã¾ãã
転ééãæ¸ããããã®æ¹æ³ã¯ããã¤ãããã¾ããããã®ä¸ã¤ã«ããã¼ã¿ãå§ç¸®ãã¦ã¬ã¹ãã³ã¹ãéä¿¡ãããã¨ããæ¹æ³ãããã¾ãã ä¾ãã°ãNginxã§ãè¨å®ã«ãã£ã¦ã¬ã¹ãã³ã¹ãã¼ã¿ãgzipå§ç¸®ãããã¨ãã§ãã¾ãã
ãã ããRestTemplateã使ã£ã¦ããå ´åãåé¡ãããã¾ãã å®ã¯ãããã©ã«ãã®RestTemplateã§ã¯gzipå§ç¸®ãããã¬ã¹ãã³ã¹ããã®ã¾ã¾ä½¿ç¨ãããã¨ãã§ããªãã®ã§ãã ã§ã¯ãã©ãããã°è¯ãã®ã§ããããã
RestTemplateã§gzipå§ç¸®ãããã¬ã¹ãã³ã¹ã使ç¨ããæ¹æ³
gzipå§ç¸®ãããã¬ã¹ãã³ã¹ã使ç¨ããã«ã¯ãRestTemplateã®å®ç¾©æã« ClientHttpRequestFactory
ã¨ãããã®ãè¨å®ããå¿
è¦ãããã¾ãã
é常RestTemplateãå®ç¾©ããéã¯
var restTemplate = new RestTemplate();
ã¨ããã¨æãã¾ãããããã
// ãã¼ã¸ã§ã³ã¯é©å®å¤æ´ãã¦ãã ãã implementation 'org.apache.httpcomponents:httpclient:4.5.13'
var clientHttpRequestFactory = new HttpComponentsClientHttpRequestFactory(HttpClientBuilder.create().build()); var restTemplate = new RestTemplate(clientHttpRequestFactory);
ã®ããã«ã ClientHttpRequestFactory
ãè¨å®ãã¾ãã
å¾ã¯ããªã¯ã¨ã¹ãæã«ãããã¼ã« Accept-Encoding
ã§gzipãè¨å®ããã°ãï¼APIå´ãgzipå§ç¸®ã«å¯¾å¿ãã¦ããã°ï¼gzipå§ç¸®ãããã¬ã¹ãã³ã¹ãåãåããèªåã§è§£åãã¦ä½¿ã£ã¦ãããããã«ãªãã¾ãã
æå¾ã«
ããã©ã«ãã§gzip解åããã¦ãããªãã¨ããã®ã¯å°ãç½ ã¿ãããªã¨ããããããè©°ã¾ã£ã¦ãã¾ã£ãæ¹ãããã®ã§ã¯ãªãã§ããããã ãã®è¨äºãåèã«ãªãã°å¹¸ãã§ãã