asp.net - Web API - Handling HEAD requests and specify custom Content-Length -


i haven api-controller serving files via get-requests. i'm using pushstreamcontentresponse , works well.

i can set content-length-header on response object.

now want support head-requests. i've tried http://www.strathweb.com/2013/03/adding-http-head-support-to-asp-net-web-api/ , while may work, need solution don't need process request: retrieving file , streaming expensive, getting meta data (length, etc) practically no-op.

however, when try set content-length header, overwritten 0.

i have added request tracing , see message returned handler displayed correct url, content-disposition , content-length.

i have tried using custom httpresponse , implement trycomputelength. , while method indeed called, result discarded @ point in pipeline.

is there way support using web api?

in end, simple.

  1. create handler head request
  2. return body @ least 1 byte content, set content-length-header of response desired length. using body 0 length won't work.
  3. this critical part: disable outputbuffering response.

the webapi will, default, disable output buffering streamcontent , pushstreamcontent. however, behavior can overridden replacing webhostbufferpolicyselector via application_startup:

globalconfiguration.configuration.services.replace(typeof (ihostbufferpolicyselector), new bufferlesshostbufferpolicyselector()); 

Comments

Popular posts from this blog

html - Firefox flex bug applied to buttons? -

html - Missing border-right in select on Firefox -

mysql - FireDac error 314 - but DLLs are in program directory -