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

feat(dynamite_runtime): make DynamiteClient extend http.Client #1580

Conversation

Leptopoda
Copy link
Member

My plan is to adapt the request manager to work with a generic http.Client and a Request.
From there the request manager can use streams, converters and whatever it needs.
This would unify/deduplicate the RequestManager.wrapUri, RequestManager.wrapBinary and RequestManager.wrapNextcloud (leaving only the webdav methods separate for now).

By creating a custom request we are able to easily change the http method to a HEAD if we decide to use it for caching later on.

Please provide feedback on the dynamite_runtime changes (should we really have that many converters?
It also contains other corrections like respecting the content-type header that I can land in separate PRs if desired.

@Leptopoda Leptopoda changed the title feat(dynamite): allow escaping reserved method names feat(dynamite_runtime): make DynamiteClient extend http.Client Feb 6, 2024
@Leptopoda Leptopoda force-pushed the refactor/dynamite_runtime/make_dynamiteClinet_a_httpClient branch from 5ce26e3 to 0486625 Compare February 6, 2024 20:28
Copy link
Member

@provokateurin provokateurin left a comment

Choose a reason for hiding this comment

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

The code looks good, but the tests are failing and I'm really seeing the direction this is going. Can you roughly explain why the changes are needed or how this will be used later on?

Comment on lines +125 to +129
if (request case DynamiteRequest(:final validStatuses)
when validStatuses != null && !validStatuses.contains(response.statusCode)) {
Copy link
Member

Choose a reason for hiding this comment

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

First I've never seen this syntax 😅 and it also is not very readable to have it all in the if statement

Copy link
Member Author

Choose a reason for hiding this comment

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

Dart3 pattern matching :P

Do you really think the usual if is easier to read?

    if (request is DynamiteRequest) {
      final validStatuses = request.validStatuses;
      if (validStatuses != null && !validStatuses.contains(response.statusCode)) {
        
      }
    }

or as we do not need the validStatuses itself

    if (request is DynamiteRequest && request.validStatuses != null 
      && !request.validStatuses!.contains(response.statusCode)) {

validStatuses is a getter so we do not get null check elevation.
I agree that it might not be strictly necessary here but I would also not be against it in general. It can help reduce a lot of boilerplate code.

Copy link
Member

Choose a reason for hiding this comment

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

Either of those options are better than the current one imo.

@Leptopoda
Copy link
Member Author

but the tests are failing

I did not add the dynamite (generator) changes yet. Neither did I add the re generated nextcloud and petstore code.
I found it easier to understand (the dynamite changes themselves might need multiple PRs as there where bigger restructures involved).

Can you roughly explain why the changes are needed or how this will be used later on?

I think the first PR post sums it up nice.
The idea came when I tried to change the request handling and decoding of images. We currently require all of them to be DynamiteRawResponses which creates some overhead. My broader goal was to make the request manager work with any type of request and response unifying the special handling we currently have for wrapUrl and wrapBinary.
I attached a patch where I realised that the current way is too complex.

request_manager.patch.txt

Signed-off-by: Nikolas Rimikis <leptopoda@users.noreply.github.com>
…ries

Signed-off-by: Nikolas Rimikis <leptopoda@users.noreply.github.com>
Signed-off-by: Nikolas Rimikis <leptopoda@users.noreply.github.com>
…spects the content-type header

Signed-off-by: Nikolas Rimikis <leptopoda@users.noreply.github.com>
Signed-off-by: Nikolas Rimikis <leptopoda@users.noreply.github.com>
…onse to DynamiteResponse

Signed-off-by: Nikolas Rimikis <leptopoda@users.noreply.github.com>
Signed-off-by: Nikolas Rimikis <leptopoda@users.noreply.github.com>
Signed-off-by: Nikolas Rimikis <leptopoda@users.noreply.github.com>
Signed-off-by: Nikolas Rimikis <leptopoda@users.noreply.github.com>
…ttp client

Signed-off-by: Nikolas Rimikis <leptopoda@users.noreply.github.com>
@Leptopoda Leptopoda force-pushed the refactor/dynamite_runtime/make_dynamiteClinet_a_httpClient branch from 0486625 to 7c33ab9 Compare February 28, 2024 17:49
@Leptopoda Leptopoda marked this pull request as ready for review February 28, 2024 17:53
@Leptopoda
Copy link
Member Author

Should be pretty ready for the next round of feedback.
@provokateurin I'll need your help with the regex magic

I didn't migrate all request manager methods yet as the PR is already enormous.
Should I split it apart?

@provokateurin
Copy link
Member

Please split everything you can, as long as it makes sense 😅 Then it can be reviewed and merged much faster.

@Leptopoda
Copy link
Member Author

Closing in favor of the separate PRs

@Leptopoda Leptopoda closed this Mar 2, 2024
@provokateurin provokateurin deleted the refactor/dynamite_runtime/make_dynamiteClinet_a_httpClient branch March 2, 2024 16:42
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.

2 participants