croservices / cro-http

HTTP (including HTTPS and HTTP/2) support for the Cro library for building distributed systems in Raku.
https://cro.services/
Artistic License 2.0
49 stars 26 forks source link

Advanced request signing using Cro::HTTP::Client #43

Open zostay opened 6 years ago

zostay commented 6 years ago

Is there a way to insert some sort of middleware into Cro::HTTP::Client after constructing the request but before transmissions? I'd like to implement AWS request signatures, but doing so requires working with a completed request. I have implemented something like this here:

https://github.com/zostay/Amazon-DynamoDB/blob/master/lib/Amazon/DynamoDB.pm6#L764

But it seems like this would be much nicer to do in the pipeline. This would need to go into the pipeline after the body has been serialized, but before transmission. I don't see a place where I can do that.

jnthn commented 6 years ago

We've considered providing for middleware in Cro::HTTP::Client, and it would be relatively easy to add; we'll give it a priority boost given somebody has a concrete use for it. :-)

For now, you could do it with with a body serializer, perhaps by making one that delegates to the standard body serializer and then adds the extra headers.