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

chore: update AliceChopperInterceptor to be compatible with Chopper v8.0.0 #180

Closed
wants to merge 7 commits into from
Closed

chore: update AliceChopperInterceptor to be compatible with Chopper v8.0.0 #180

wants to merge 7 commits into from

Conversation

techouse
Copy link
Collaborator

@techouse techouse commented Jun 4, 2024

Hey 👋

Recently I stumbled upon this awesome package and I noticed it (also) uses Chopper Interceptors.

In Chopper v8.0.0, there was a significant restructuring of interceptors. The RequestInterceptor and ResponseInterceptor classes, as well as their function counterparts, were removed.

Since I'm one of the maintainers of Chopper I thought I'd contribute to this library by updating the AliceChopperInterceptor to be compatible with Chopper v8.0.0.

CC / @Guldem

Copy link

@Guldem Guldem left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got some feedback :)

lib/core/alice_chopper_response_interceptor.dart Outdated Show resolved Hide resolved
lib/core/alice_chopper_response_interceptor.dart Outdated Show resolved Hide resolved
lib/core/alice_chopper_response_interceptor.dart Outdated Show resolved Hide resolved

String? contentType = 'unknown';
if (request.headers.containsKey('Content-Type')) {
contentType = request.headers['Content-Type'];
if (chain.request.headers.containsKey('Content-Type')) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Content-Type string could be const I guess and would case insensitive be needed?

Copy link
Collaborator Author

@techouse techouse Jun 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, not sure. For that I'd need to import dart:io, I think. Is this package supposed to work on web?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well it feels like something that could be shared between the different clients (dio, http, chopper). I suppose they all have this logic. Of course with web support in mind.

Copy link
Collaborator Author

@techouse techouse Jun 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't look like this package has web in mind, so I'll just use the constants from dart:io.

lib/core/alice_chopper_response_interceptor.dart Outdated Show resolved Hide resolved

/// Adds data to existing alice http call
aliceCore.addResponse(
Copy link

@Guldem Guldem Jun 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure but I don't think its needed to add the Response afterwards. My guess is the hashcode and this function where used because the previous request and response callback we're separate. But with the new Interceptors this in not the case any more. So you can proceed the request and attach the response directly to the same AliceCall.

I also think changing this will remove the need for adding a alice_token header.

Copy link
Collaborator Author

@techouse techouse Jun 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I moved the AliceHttpResponse to the AliceHttpCall, however, I kept the alice_token cause I'm not 100% sure if it's needed for any other purpose. Maybe @jhomlala can give some more info here?

@jhomlala
Copy link
Owner

jhomlala commented Jun 5, 2024

Hi everyone! I've just released new version of Alice which splits clients into separate packages. There's new alice + chopper package here: https://github.com/jhomlala/alice/tree/master/packages/alice_chopper . I've updated chopper to 8.0.0 in this package. Can you verify if we are aligned with our changes?

@Guldem
Copy link

Guldem commented Jun 5, 2024

Hi everyone! I've just released new version of Alice which splits clients into separate packages. There's new alice + chopper package here: https://github.com/jhomlala/alice/tree/master/packages/alice_chopper . I've updated chopper to 8.0.0 in this package. Can you verify if we are aligned with our changes?

Very nice improvement of splitting into different packages ❤️. Looking at the interceptor code I think the implementation of @techouse is a bit cleaner. So I would suggest aligning these changes 😄

Also we still have an open question about the alice_token and hashcode implementation if that's still relevant with the updated chopper interceptor functionality.

Thanks for all your work!

@techouse
Copy link
Collaborator Author

techouse commented Jun 5, 2024

Hi everyone! I've just released new version of Alice which splits clients into separate packages. There's new alice + chopper package here: https://github.com/jhomlala/alice/tree/master/packages/alice_chopper . I've updated chopper to 8.0.0 in this package. Can you verify if we are aligned with our changes?

Very nice improvement of splitting into different packages ❤️. Looking at the interceptor code I think the implementation of @techouse is a bit cleaner. So I would suggest aligning these changes 😄

Also we still have an open question about the alice_token and hashcode implementation if that's still relevant with the updated chopper interceptor functionality.

Thanks for all your work!

Ha, looks like I jumped the gun on this one 😂 I'll check out the changes in the evening.

@Guldem
Copy link

Guldem commented Jun 5, 2024

Hi everyone! I've just released new version of Alice which splits clients into separate packages. There's new alice + chopper package here: https://github.com/jhomlala/alice/tree/master/packages/alice_chopper . I've updated chopper to 8.0.0 in this package. Can you verify if we are aligned with our changes?

Very nice improvement of splitting into different packages ❤️. Looking at the interceptor code I think the implementation of @techouse is a bit cleaner. So I would suggest aligning these changes 😄
Also we still have an open question about the alice_token and hashcode implementation if that's still relevant with the updated chopper interceptor functionality.
Thanks for all your work!

Ha, looks like I jumped the gun on this one 😂 I'll check out the changes in the evening.

Haha, nah it just moved somewhere else 😉

# Conflicts:
#	packages/alice/lib/alice.dart
#	packages/alice_chopper/lib/alice_chopper_response_interceptor.dart
#	pubspec.lock
#	pubspec.yaml
@techouse techouse closed this Jun 5, 2024
@techouse
Copy link
Collaborator Author

techouse commented Jun 5, 2024

This PR is a mess because of the recent changes. I have created #185 to supersede it.

@techouse techouse deleted the chore/chopper-v8 branch June 5, 2024 18:39
@jhomlala
Copy link
Owner

jhomlala commented Jun 5, 2024

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants