0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

API Gatewayでgzipが有効かcurlを利用して確認する方法

Posted at

Nuxt.jsのgzip機能を検証するのにAPI Gatewayのエンドポイントでgzip圧縮が有効かcurl で確認していたのですが、そのときにわかったオプションの利用方法についてまとめました。

API Gatewayでは-i オプションで確認する

実際にgzipが有効なAPI Gatewayのエンドポイントで試してみます。
-I オプションでHeaderのみ取得します。

> curl -I -H 'Accept-Encoding: gzip,deflate' https://xxxxxxxxxx.execute-api.ap-northeast-1.amazonaws.com/dev/

HTTP/2 200
content-type: text/html; charset=utf-8
content-length: 1887
date: Wed, 14 Nov 2018 04:36:25 GMT
x-amzn-requestid: d810a342-e7c6-11e8-a275-c181ecb58436
x-amzn-remapped-content-length: 1887
x-amz-apigw-id: QVbrZHWFtjMFRlQ=
vary: Accept-Encoding
x-powered-by: Express
x-amzn-trace-id: Root=1-5beba648-ea3c9a54a60a0c3010121cf0;Sampled=0
x-cache: Miss from cloudfront
via: 1.1 13f9acb9132808e8bc1d9cdb66665fd2.cloudfront.net (CloudFront)
x-amz-cf-id: GEfg6hZZ7Q0ZSpOHITs4w1JdeHqWnsXRTzoVMqrxe4SQRIubAqzddg==

はい。
content-encoding: gzip がありません。

-i オプションでBodyも合わせて取得してみます。

> curl -i -H 'Accept-Encoding: gzip,deflate' https://xxxxxxxxxx.execute-api.ap-northeast-1.amazonaws.com/dev/

HTTP/2 200
content-type: text/html; charset=utf-8
content-length: 713
date: Wed, 14 Nov 2018 04:37:17 GMT
x-amzn-requestid: f72be533-e7c6-11e8-816a-6bda176640bb
content-encoding: gzip
x-amz-apigw-id: QVbzjH91NjMFfOw=
vary: Accept-Encoding
x-powered-by: Express
x-amzn-trace-id: Root=1-5beba67d-eedd4e78b2aca1ac1dc09830;Sampled=0
x-cache: Miss from cloudfront
via: 1.1 c0e128ce87e0e7831036286606c64e34.cloudfront.net (CloudFront)
x-amz-cf-id: -E9TiEC9mDdPyrfF70uPmE0O0IKXaonk_ksBUem60lKsLjW6__uOLQ==

�UMo�0
      ��Whv���$v��n;
                    =�6`Y�c��eHJڠ��d']Z4]��,�z�|�I���f�j�Z�W�{ F
                                                                �Z��<������B(w{��[Í��w��.?�r��7݀ڂ�5��u'��<�e�C��#���xcj/���-YC���;��E��@k�����`����0B���iJ�{������@S�;�e{p�����Z�F���-7
D�9u<�����6�p�d�̾]�"7���){|gWI>��lm4�t
i�1Ic2���EQ���]�AùL0�R��z<%�"��'�eL�*�njUs�TI=N"����     8����4���t��,�h>�P]:c�%l�"�@ϒ8��b��Q�I5O�iDf    0�n�zn���I��
����lOA�@���Zd�;�Q��Tm�:��)�R���G���,��h������EE��J�M�<*�TY%�e!;B��e���y��      ���W;��������S��B?�c+>*Qޕ7d��y��Dג�-J�(��}�~���u"-���Xr�o7J�������*���{e��,�y�/���~�.���9�ӧ&�ȕ%������
                                                                  _�?��R6��F���>�=ڔi;�2ܧ
?�����>s�Z��>�}�H+z���@��ğl�3�'�֙�����%�B�7
                                          ��?�3��_⏎

content-encoding: gzip が付きました。なんで?

他のサイトは-I オプションで大丈夫(っぽい)

API Gatewayのエンドポイントを利用していなさそうなサイトで確認してみます。

> curl -I -H 'Accept-Encoding: gzip,deflate' https://qiita.com

HTTP/2 200
date: Wed, 14 Nov 2018 04:40:25 GMT
content-type: text/html; charset=utf-8
server: nginx
x-frame-options: SAMEORIGIN
x-xss-protection: 1; mode=block
x-content-type-options: nosniff
etag: W/"35a6585bbe0ad2d1ef8c3f53e8882d8e"
cache-control: max-age=0, private, must-revalidate
set-cookie: _qiita_login_session=dmlTUS9HVjRnSUs1b2JpS2QzSWttL3VxSlpnM0RpTlNrMnl2cnp2ZUhTYUE4aC8vY3pZTjRSWE9OMlVGcXBySktVcmw2dklodTBMcjVBU3lhUDdPQkw0dk55T2orc0FOb3I3UG92MkRHZytiekdkd3JoUDk0MU9IVEdpemJSUW1INkdtRUpSaDlqZ0tHcXdRcE9OOWxuZGg4WWFPMXRFK0FBMHBWZ0oxWk9Rd2QvUDJITG1BcWtkSDIva3RRQVJ4LS1OK2pRNHQ4MHRsTjBDTHh0Vy9XN3VnPT0%3D--7368e2740a4c60dc13e235bf32b4bc3e26a04734; domain=.qiita.com; path=/; expires=Thu, 14 Nov 2019 04:40:25 -0000; HttpOnly
x-runtime: 0.136748
strict-transport-security: max-age=2592000
x-request-id: f7138814-44ff-4d74-8163-ddf9ebcffa49
content-encoding: gzip
> curl -i -H 'Accept-Encoding: gzip,deflate' https://qiita.com

HTTP/2 200
date: Wed, 14 Nov 2018 04:40:49 GMT
content-type: text/html; charset=utf-8
server: nginx
x-frame-options: SAMEORIGIN
x-xss-protection: 1; mode=block
x-content-type-options: nosniff
etag: W/"21cf86018eed14eac764c519337453e6"
cache-control: max-age=0, private, must-revalidate
set-cookie: _qiita_login_session=xxx; domain=.qiita.com; path=/; expires=Thu, 14 Nov 2019 04:40:49 -0000; HttpOnly
x-runtime: 0.160464
strict-transport-security: max-age=2592000
x-request-id: 041b5079-05bb-4da7-be4c-2f358bcf5048
content-encoding: gzip}{w��|��Y�����_���1�A��Bఴ���&�4bfd��d�ئ�z�-Ph�
�KK��iK[Z�z��b'���Gx{ό��F���t�����}y�����綟}�[���_�x�P����C�'%��&����I�xf�{%sJ�����Ag��~LU�i٠�ʮ�n\�q�������c�4J�CtFւ�֠�ȏii����;$��o�h�zH���J��|�Fq�R�ކ�13�=�i+�$t����FZ:y0%p��Lq\��Z �v#�ү���Tj�z48j�6��!�&"y"�h���LM       Q�?�8nGӕ����a������3��:-��&��x�^�r�� a��iD�z/r�Rt�a�EW�GILx����s'hy~
 Bw��T�#+hE�Z~�Mc�
                  B�YF���&      �i�jBM�8k
(略)

Qiitaさんは-I-i の両方でcontent-encoding: gzip が含まれています。

API Gatewayだけの問題なのでしょうか?

参考

curl コマンド 使い方メモ - Qiita
https://qiita.com/yasuhiroki/items/a569d3371a66e365316f

Nginxのgzipが動いているか確認する方法 ~ クライアントサイド~ - Qiita
https://qiita.com/ukitazume/items/fff67c15da7b81cfa6ac

0
0
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?