Skip to content

Comments

Take advantage of improvement in the http crate for cloning#7559

Merged
garypen merged 5 commits intodevfrom
garypen/http_ext_clone_works_properly
May 30, 2025
Merged

Take advantage of improvement in the http crate for cloning#7559
garypen merged 5 commits intodevfrom
garypen/http_ext_clone_works_properly

Conversation

@garypen
Copy link
Contributor

@garypen garypen commented May 23, 2025

In an older version of the crate, http::Extensions were not Clone. This had the consequence that http::Request and http::Response were also not clone. To work-around this limitation, we had functions in our http_ext module which would "clone" a Request or a Response, but they'd omit Extensions.

Generally speaking, this wasn't a problem for most use cases. However, over time we started to add functionality, such as file uploads, to the router which relied on the correct behaviour of cloning and expected Extensions to be preserved across a clone.

This finally resulted in an issue for a customer who could not understand why modifying a request in a Rhai script would cause a File Upload to fail.

It transpires that at version 1.0.0 of the http crate, an incompatible change was made which forces http::Extensions to be Clone which means both http::Request and http::Response are now Clone.

I've replaced our http::Extensions ignoring implementation with the provided Clone behaviour and this means that Request and Response Extensions are now correctly cloned. I've added tests for this as well.

Note: This can't be easily back-ported to 1.x. http is used all over the place and a test compile results in:

error: could not compile `apollo-router` (lib) due to 114 previous errors

I think that updating the code would be very intrusive.


Checklist

Complete the checklist (and note appropriate exceptions) before the PR is marked ready-for-review.

  • Changes are compatible1
  • Documentation2 completed
  • Performance impact assessed and acceptable
  • Tests added and passing3
    • Unit Tests
    • Integration Tests
    • Manual Tests

Exceptions

Note any exceptions here

Notes

Footnotes

  1. It may be appropriate to bring upcoming changes to the attention of other (impacted) groups. Please endeavour to do this before seeking PR approval. The mechanism for doing this will vary considerably, so use your judgement as to how and when to do this.

  2. Configuration is an important part of many changes. Where applicable please try to document configuration examples.

  3. Tick whichever testing boxes are applicable. If you are adding Manual Tests, please document the manual testing (extensively) in the Exceptions.

In an older version of the crate, `http::Extensions` were not `Clone`. This
had the consequence that `http::Request` and `http::Response` were also
not clone. To work-around this limitation, we had functions in our
http_ext module which would "clone" a `Request` or a `Response`, but
they'd omit `Extensions`.

Generally speaking, this wasn't a problem for most use cases. However,
over time we started to add functionality, such as file uploads, to the
router which relied on the correct behaviour of cloning and expected
Extensions to be preserved across a clone.

This finally resulted in an issue for a customer who could not
understand why modifying a request in a Rhai script would cause a File
Upload to fail.

It transpires that at version 1.0.0 of the http crate, an incompatible
change was made which forces `http::Extensions` to be `Clone` which means
both `http::Request` and `http::Response` are now `Clone`.

I've replaced our `http::Extensions` ignoring implementation with the
provided `Clone` behaviour and this means that Request and Response
Extensions are now correctly cloned. I've added tests for this as well.
@garypen garypen self-assigned this May 23, 2025
@garypen garypen requested a review from a team May 23, 2025 13:45
@github-actions

This comment has been minimized.

@svc-apollo-docs
Copy link
Collaborator

svc-apollo-docs commented May 23, 2025

✅ Docs preview has no changes

The preview was not built because there were no changes.

Build ID: 9fca2c2268b1f88159a19fe1

@DaleSeo DaleSeo mentioned this pull request May 23, 2025
6 tasks
@garypen garypen requested a review from a team as a code owner May 23, 2025 15:17
@garypen garypen requested a review from goto-bus-stop May 27, 2025 06:47
Copy link
Member

@goto-bus-stop goto-bus-stop left a comment

Choose a reason for hiding this comment

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

I'd like to see an integration test that uses file upload + rhai...

@garypen
Copy link
Contributor Author

garypen commented May 28, 2025

I'd like to see an integration test that uses file upload + rhai...

That's a great suggestion. I've got no idea how I'd do that right now, but I'll take a look through the existing File Upload Integration Tests and see if I can figure something out.

@garypen
Copy link
Contributor Author

garypen commented May 28, 2025

I'd like to see an integration test that uses file upload + rhai...

That's a great suggestion. I've got no idea how I'd do that right now, but I'll take a look through the existing File Upload Integration Tests and see if I can figure something out.

It was surprisingly easy: 15bc639. Well done to the author of the original File Upload Integration Tests!

@garypen garypen requested a review from goto-bus-stop May 28, 2025 16:05
Copy link
Member

@goto-bus-stop goto-bus-stop left a comment

Choose a reason for hiding this comment

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

lovely 😁

@garypen garypen enabled auto-merge (squash) May 30, 2025 11:00
@garypen garypen merged commit ceb54bc into dev May 30, 2025
15 checks passed
@garypen garypen deleted the garypen/http_ext_clone_works_properly branch May 30, 2025 11:16
@abernix abernix mentioned this pull request Jul 1, 2025
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