Skip to content

Commit

Permalink
Merge pull request #96 from microsoftgraph/bugfix/ranges-and-compression
Browse files Browse the repository at this point in the history
fix: adds content-encoding and range precisions
  • Loading branch information
baywet authored Jul 15, 2024
2 parents f12d25c + 1d0ee15 commit f8a12ff
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
4 changes: 3 additions & 1 deletion middleware/CompressionHandler.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@ A middleware component that compresses request bodies and falls back to an uncom

- Add `Content-encoding: gzip` to request headers for requests with a body.
- Compresses request bodies.
- Should the handler receive a [415 Unsupported Media Type](https://httpwg.org/specs/rfc7231.html#status.415) response or a `400 Bad Request` response with an OData error containing the following message `Unable to read JSON request payload. Please ensure Content-Type header is set and payload is of valid JSON format.` when the content-type was `application/json`, the handler will retry sending the request without compressing it a maximum of one time before passing on the error.
- Should the handler receive a [415 Unsupported Media Type](https://httpwg.org/specs/rfc7231.html#status.415) response, the handler will retry sending the request without compressing it a maximum of one time before passing on the error.
- Compression handler should be installed as a default handler by [GraphClientFactory](../GraphClientFactory.md)
- The compression handler should accept a `CompressionOptions` object with a property `EnableCompression`. That object can be passed when instantiating the handler, if nothing is passed a default value is created with `EnableCompression: true`. That object can also be passed on a per request base from the fluent-style API by the SDK used. If a value is passed for the request, it takes precedence over the value that was set with the handler. Compression is only performed when the computed value of `EnableCompression` is `true`.
- MUST NOT compress request bodies when a Content-Range header is present with a "bytes" range unit to avoid "corrupting" the set of requests in the range. (e.g. Content-Range: bytes 0-9/20)
- MUST NOT compress request bodies when a Content-Encoding header is already present to avoid double compression.

## Remarks

Expand Down
6 changes: 6 additions & 0 deletions tasks/FileUploadTask.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ This task aims to provide a fluent and easy to use mechanism for the consumer to
- The task should be agnostic to the kind of upload being performed so as to support for various fileUpload scenarios e.g. **DriveItem** and **FileAttachment**. An example of the agnostic nature of task is how the task is marked as completed considering different response formats from each API:
- If the response status is a 201.
- An additional case for OneDrive is, if the response status is a 200 and the response contains an "id" then the task is complete.
- MUST NOT compress the individual slices when it uploads them. This is because compressing slices with content-encoding header leads to invalid ranges/content length headers. (e.g. for a 100 bytes file of 10*10 bytes uncompressed slices, the content length would be ~7 bytes)
- MUST NOT compress the whole file before sending it. This is because it might lead to memory issues in some client contexts (needs compressed result length to [compute the range header](https://www.rfc-editor.org/rfc/rfc9110.html#section-14.1.2-3)), it's also because the content-encoding header applies to individual requests and not to the overall set of requests and the server would try to decompress each slice independently, leading to a corrupted result.

> Note: Outlook and Print API does not allow to update an attachment after it has been uploaded.
Expand All @@ -39,6 +41,10 @@ Refer to the following documentation for more information:
- [OneDriveItem](https://docs.microsoft.com/en-us/graph/api/driveitem-createuploadsession?view=graph-rest-1.0&preserve-view=true)
- [Print API](https://docs.microsoft.com/en-us/graph/upload-data-to-upload-session)

### Appendix on the range header for Microsoft Graph

Microsoft Graph large file upload is inspired off [range response syntax](https://www.rfc-editor.org/rfc/rfc7233#section-4.2), [updated in RFC9110](https://www.rfc-editor.org/rfc/rfc9110.html#section-14.1.2).

## Large File Upload Session

Json Schema of the upload session object:
Expand Down

0 comments on commit f8a12ff

Please sign in to comment.