开发者

how to forward a request with original headers intact

I'm trying to write an ASP.NET http handler with the following purpose: On incoming requests, do some checking on parameters, look up a URL in a database, log the request, and if everything is alright, forward the request (or return the file in the response).

It's almost straight forward. The problem is that the request is a partial http request (it includes a range header), and the client expects a partial response. I try to use server.transfer in order to transfer the request to the correct file. Something like this:

public class Redirecter : IHttpHandler
{
    public void ProcessRequest(HttpContext context)
    {
        //Check stuff
        ............
        if( everyThingOk )
        {
             context.Server.Transfer("/Temp/the/file");
        }
        else
        {
            //respond with some error
        }
    }
    ........
}

Problem is that the transfer doesn't seem to respect the original request headers. I have no handler or anything installed for the URL where I redirect the request to, so I just expect it to be a normal file download. But since the original request include a Range header I would expect the response to be a partial respnse, but it's not.

Request:

GET /Some/file HTTP/1.1
Range:bytes=0-4999               <----only want 5000 bytes

Response:

HTTP/1.1 200 OK          <-------- what? Expecte开发者_Python百科d 206!
Server:ASP.NET Development Server/10.0.0.
Date:Tue, 06 Sep 2011 09:21:07 GMT
X-AspNet-Version:4.0.30319
Cache-Control:private
Content-Type:text/html
Content-Length:79051  <----- too large, only expected 5000 bytes max
Connection:Close

And I'm missing a Content-Range header as well. So it seems a header is lost in the transfer?

I don't NEED to do a transfer, it was just what I thought was the most simple way to do this.

How do I do the 'transfer' correctly so I respect the partial request?


Why don't you call the Asp.Net request handler directly ? Is it HttpApplication ?


You might want to read those headers from the request; build a Web request with them; Ex:

            HttpWebRequest httpWebRequest = HttpWebRequest.Create("absolutepath") as HttpWebRequest;
            httpWebRequest.Headers["Content_Length"] = this.Request.ServerVariables["Content_Length"];
            httpWebRequest.Headers["Content_Range"] = this.Request.ServerVariables["Content_Range"];

            // Create expects absolute path..
            // you might have to build an absolute path location for the temp file
            HttpWebResponse response =  httpWebRequest.GetResponse() as HttpWebResponse; 
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜