Skip to the content.

Compression Handler

A middleware component that compresses request bodies and falls back to an uncompressed body if the API doesn’t support request body compression.

Requirements

Remarks

For response payload decompression, refer to the decompression handler specification.

This handler MUST be inserted BEFORE the Retry handler to avoid compressing the request payload multiple times over.

This handler is part of the Graph handlers collection and not the Kiota handler collection because of how it handles bad requests being specific to Microsoft Graph APIs.

Microsoft Graph environments which do not support request body compression yet return a 400 response code instead of 415.

Example

HTTP request with compressed body

POST https://graph.microsoft.com/v1.0/me/microsoft.graph.sendMail HTTP/1.1
Host: graph.microsoft.com
SdkVersion: Graph-dotnet-2.0.5
FeatureFlag: 00000047
Cache-Control: no-store, no-cache
Authorization: Bearer {token}
Accept-Encoding: gzip
Transfer-Encoding: chunked
Content-Type: application/json
Content-Encoding: gzip
…compressed body….

HTTP response from Microsoft Graph when request compression is not supported

HTTP/1.1 400 Bad Request

Date: Thu, 09 Dec 2021 03:37:07 GMT

Content-Type: application/json

Vary: Accept-Encoding

Strict-Transport-Security: max-age=31536000

request-id: 38b4ee5c-1168-4281-863b-920860a4eebe

client-request-id: 38b4ee5c-1168-4281-863b-920860a4eebe

x-ms-ags-diagnostic: {"ServerInfo":{"DataCenter":"Canada East","Slice":"E","Ring":"2","ScaleUnit":"001","RoleInstance":"QB1PEPF0000111E"}}

Content-Length: 313

 

{"error":{"code":"BadRequest","message":"Unable to read JSON request payload. Please ensure Content-Type header is set and payload is of valid JSON format.","innerError":{"date":"2021-12-09T03:37:08","request-id":"38b4ee5c-1168-4281-863b-920860a4eebe","client-request-id":"38b4ee5c-1168-4281-863b-920860a4eebe"}}}