mardi 29 septembre 2015

Inspect HttpRequestMessage just before it is sent

I have been tasked with integrating with the Amazon Gift Codes On Demand (AGCOD) RESTful API. We are required to sign our requests using Signature Version 4, something that is performed by their AWS SDK for .NET for other services, but not AGCOD.

I am using the HttpClient class from the System.Net.Http namespace to communicate with AWS's API. This in turn is using the HttpClientHandler to create an HttpRequestMessage. In so doing extra headers like Host, Content-Length and Connection are added to the message.

My question is, how do I go about inspecting the message after I have called PostAsync and the headers have been added, but before it is sent to the server so I can compute and add the signature?

I could obviously simply just specify these headers myself. But that only helps for known headers. If a different HttpMessageHandler is used (e.g. the WebRequestHandler) then different headers may be added (for example Content-Encoding and Cache-Control). If I don't know about all the headers in the message I will not be able to compute the correct signature.




Aucun commentaire:

Enregistrer un commentaire