Skip to content
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

Multiple cache-control headers are not handled #14

Closed
tjarvstrand opened this issue Jun 22, 2021 · 4 comments
Closed

Multiple cache-control headers are not handled #14

tjarvstrand opened this issue Jun 22, 2021 · 4 comments
Assignees
Labels
bug Something isn't working
Projects

Comments

@tjarvstrand
Copy link
Contributor

tjarvstrand commented Jun 22, 2021

Describe the bug
While debugging some code I came across a situation where the server returned a response with multiple cache-control header values. This is valid according to RFC2616 but it will currently cause stash_dio to throw an exception ('"cache-control" header has more than one value, please use Headers[name]')

To Reproduce
Make a request to an endpoint returning several cache-control header values

Expected behavior
The values are concatenated, interspersed with commas

Version
Flutter 2.2.0 • channel stable • https://github.com/flutter/flutter.git
Framework • revision b22742018b (5 weeks ago) • 2021-05-14 19:12:57 -0700
Engine • revision a9d88a4d18
Tools • Dart 2.13.0

Additional context
Relevant section of RFC2616
Stack overflow question

@github-actions github-actions bot added this to To do in stash Jun 22, 2021
@tjarvstrand
Copy link
Contributor Author

This interceptor seems to function as a workaround:

static final _cacheControlWrapper = InterceptorsWrapper(
    onResponse: (response, handler) {
      final cacheControl = response.headers["cache-control"];
      if (cacheControl != null && cacheControl.length > 1) {
        response.headers.set("cache-control", cacheControl.join(","));
      }
      handler.next(response);
    },
  );

@ivoleitao ivoleitao self-assigned this Jun 22, 2021
@ivoleitao ivoleitao added the enhancement New feature or request label Jun 22, 2021
@ivoleitao
Copy link
Owner

Thanks for the report @tjarvstrand I will take a look at this during the weekend

@ivoleitao ivoleitao moved this from To do to In progress in stash Jun 23, 2021
@ivoleitao
Copy link
Owner

Fixed, it was easy to simulate although your complete description helped a lot. I've added a unit test for this and actually used a similar solution as the one you employed on the workaround as per RFC spec two separate cache-control headers are the same as one with the values separated by commas. It's now available on the latest version of stash_dio ^3.0.2

stash automation moved this from In progress to Done Jun 25, 2021
@ivoleitao ivoleitao added bug Something isn't working and removed enhancement New feature or request labels Jun 26, 2021
@tjarvstrand
Copy link
Contributor Author

Great! Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
No open projects
stash
Done
Development

No branches or pull requests

2 participants