agbodike
agbodike

Reputation: 1846

Compressed JSON Content Type

I'm integrating a 3rd party API, and at one step they post JSON data into our server.

The content type they are sending is application/json, but the payload is actually gzipped, is this valid? I believe it should be gzip/json content type.

Update 1

the env["RAW_POST_DATA"] contains binary data, rather than JSON in text format that I would expect.

Update 2

This is a fairly standard Rails application, hosted on heroku with Puma for staging and production.

Update 3

I've not debugged at this level on heroku previously, so it's possible that I'm missing something, but I do not see a content-encoding header (I did miss the "HTTP_CONTENT_ENCODING"=>"gzip" header). The headers that I do get are:

2015-12-04T08:00:08.001620+00:00 app[web.1]: D, [2015-12-04T08:00:08.001590 #7] DEBUG -- : REQUEST_PATH: /
2015-12-04T08:00:08.001660+00:00 app[web.1]: D, [2015-12-04T08:00:08.001620 #7] DEBUG -- : REQUEST_URI: /
2015-12-04T08:00:08.001701+00:00 app[web.1]: D, [2015-12-04T08:00:08.001656 #7] DEBUG -- : HTTP_VERSION: HTTP/1.1
2015-12-04T08:00:08.001735+00:00 app[web.1]: D, [2015-12-04T08:00:08.001698 #7] DEBUG -- : HTTP_HOST: staging.redacted.com
2015-12-04T08:00:08.001768+00:00 app[web.1]: D, [2015-12-04T08:00:08.001732 #7] DEBUG -- : HTTP_CONNECTION: close
2015-12-04T08:00:08.001801+00:00 app[web.1]: D, [2015-12-04T08:00:08.001765 #7] DEBUG -- : HTTP_ACCEPT:
2015-12-04T08:00:08.001823+00:00 app[web.1]: D, [2015-12-04T08:00:08.001798 #7] DEBUG -- : CONTENT_LENGTH: 277
2015-12-04T08:00:08.001861+00:00 app[web.1]: D, [2015-12-04T08:00:08.001826 #7] DEBUG -- : CONTENT_TYPE: application/json
2015-12-04T08:00:08.001918+00:00 app[web.1]: D, [2015-12-04T08:00:08.001858 #7] DEBUG -- : HTTP_CACHE_CONTROL:
2015-12-04T08:00:08.001920+00:00 app[web.1]: D, [2015-12-04T08:00:08.001891 #7] DEBUG -- : HTTP_ORIGIN:
2015-12-04T08:00:08.001958+00:00 app[web.1]: D, [2015-12-04T08:00:08.001921 #7] DEBUG -- : HTTP_USER_AGENT: Apache-HttpClient/4.3.4 (java 1.5)
2015-12-04T08:00:08.001996+00:00 app[web.1]: D, [2015-12-04T08:00:08.001953 #7] DEBUG -- : HTTP_POSTMAN_TOKEN:
2015-12-04T08:00:08.002029+00:00 app[web.1]: D, [2015-12-04T08:00:08.001992 #7] DEBUG -- : HTTP_DNT:
2015-12-04T08:00:08.001801+00:00 app[web.1]: D, [2015-12-04T08:00:08.001765 #7] DEBUG -- : HTTP_CONTENT_ENCODING: gzip
2015-12-04T08:00:08.002074+00:00 app[web.1]: D, [2015-12-04T08:00:08.002027 #7] DEBUG -- : HTTP_ACCEPT_ENCODING: gzip,deflate
2015-12-04T08:00:08.002093+00:00 app[web.1]: D, [2015-12-04T08:00:08.002061 #7] DEBUG -- : HTTP_ACCEPT_LANGUAGE:
2015-12-04T08:00:08.002137+00:00 app[web.1]: D, [2015-12-04T08:00:08.002094 #7] DEBUG -- : HTTP_COOKIE:

And the raw post data prints out as:

2015-12-04T08:00:08.002165+00:00 app[web.1]: D, [2015-12-04T08:00:08.002128 #7] DEBUG -- : RAW_POST_DATA:
2015-12-04T08:00:08.002166+00:00 app[web.1]:
2015-12-04T08:00:08.002168+00:00 app[web.1]: ���_%���R�@�S%@�4ݶ��n���wg�4$Wz��9�/me�J���pоp     Eٍ��!B�,N��@��k4g�
2015-12-04T08:00:08.002169+00:00 app[web.1]: -���*c�8�[�PK&DفR���LM�
2015-12-04T08:00:08.002169+00:00 app[web.1]: k=t@:?"'��Ip|�dpg��縼Ѻ|�u�cBC��Hly��*�ǯ'Meq�W�]N͛C�F

Upvotes: 0

Views: 7887

Answers (1)

Julian Reschke
Julian Reschke

Reputation: 42025

So the request body is gzipped, and the request carries "Content-Encoding: gzip". No surprises here. See RFC 7231 Section 3.1.2 Encoding for Compression or Integrity.

Upvotes: 2

Related Questions