-
Notifications
You must be signed in to change notification settings - Fork 33
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: request body compression #1358
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work getting started on this!
packages/http/fetch/src/middlewares/options/compressionHandlerOptions.ts
Outdated
Show resolved
Hide resolved
21ece56
to
9381806
Compare
@rkodev the compression stream API is available on 90+% of browsers out there, we should use that for browsers and assume if applications run into an issue they can selectively disable the middleware based on the browser they want to support. As for nod ethe zlib gzip API is available since "forever" The way around the issue you're facing is to:
I think we have other examples of doing that across the code. If this is two complex, we could have two implementations of the middleware (a bit more duplication) and insert the right implementation in the right factory (we already have that in place as well) Let me know if you have any additional comments or questions. |
packages/http/fetch/src/middlewares/options/compressionHandlerOptions.ts
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for making the changes!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for making the changes!
Signed-off-by: Vincent Biret <vibiret@microsoft.com>
@baywet Thanks for taking a look |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please also add a config to remove this line as well. (I should have used a different approach to set a marker for the release)
"last-release-sha": "f13c350c40b76f7dff25e71e6ceeeb0066aa02be", |
It took me a while to track this bug down! Enabling request body compression by default broke several of my clients. Could it be an optional middleware that’s not enabled by default? |
@jlarmstrongiv thanks for reporting this. Can you share more information as to how were your clients brokens? Did the target service not support decompress request bodies? or was something wrong with how the middleware handles the compression/headers? The design is to enable it by default across languages, of course you always have the option to disable it for a specific client. Additionally, was your client running as a node or a browser application? @rkodev to follow up on that as I'll be out of office soon. |
While the kiota client supports compressed request bodies just fine, the API I use does not. Instead, the I would like to avoid having the request compression middleware enabled by default on all languages and avoid running into this issue 5 more times. Or, at least, have an example on how to disable the middleware for each language (typescript, python, php, java, c#, go). I run the client as both a Node.js and Browser application. It’s the server that has the issue, and it’s a server I do not have control over. Without the request content encoding, everything works great. |
Thank you for the additional information. Is this server not supporting compression for all operations/paths or just for a few? The reason why I'm asking is because you can pass a per request option if this is just for a few to disable body compression on a per request base. Otherwise your best bet is to copy the middleware and client factory to tweak which handlers are selected before passing things to the request adapter. This advice applies to all languages as this is the general design of the middleware + options + client part of the infrastructure. As for the fact that the compression handler has been added in a preview bump, while this is an important behavior change, it's not an API breaking change, and TypeScript is still in preview anyway, be aware that other changes of the sort might happen before the language reaches a stable maturity. |
Thank you for your help! Unfortunately, it’s all operations. I tried the following code: const httpClient = new HttpClient(
undefined,
new RetryHandler(),
new RedirectHandler(),
new ParametersNameDecodingHandler(),
new UserAgentHandler(),
new HeadersInspectionHandler(),
);
const fetchAdapter = new FetchRequestAdapter(
authenticationProvider,
undefined,
undefined,
httpClient,
); But I receive the error
I have subscribed to all issues related to request compression to ensure I am notified when breaking changes occur. In the several months I’ve worked with kiota, this issue is the first to have caused outages. |
Thank you for the additional information. Can you try the following? It's not the most obvious way of setting it up. const httpClient = new HttpClient(
- undefined,
+ fetch,
new RetryHandler(),
new RedirectHandler(),
new ParametersNameDecodingHandler(),
new UserAgentHandler(),
new HeadersInspectionHandler(),
); |
Yes, that worked! Thank you. Interesting that it needs the |
Resolves #1288
Adds support for compression of request body