Accessing Request Headers inside Formatter

Topics: Web Api
Nov 17, 2011 at 10:20 AM


I have a requirement where client specifies the properties he wants as a "," delimited string in the form a Request.Header . I am planning to implement this as a Formatter. How can we get access to HttpHeaders from inside the OnWriteToStream method.

Thanks in Advance.

Nov 17, 2011 at 6:49 PM

Currently you can’t get access to the request directly from a formatter. You only have access to the HttpContent for the response. This is a known issue that we are investigating a solution for.

As a workaround you can try to tunnel data through the HttpContent headers. The headers will get written to the wire though.

Alternatively you could use an HttpOperationHandler on the response.

Daniel Roth

Nov 18, 2011 at 9:14 PM
Edited Nov 18, 2011 at 11:14 PM

As Dan mentioned above you can try to tunnel data through HttpContent headers in a response HttpOperationHandler...and later in the formatter, you can access these Content headers to do any customization of the format...


Kiran Challa