0

I just wrote an SSL supporting HTTP 1.1/1.0 proxy putting together some code for past two days. I used the HTTPWebResponse/HTTPWebRequest class to get the data from the Server. While relaying data from the server I send the headers first to the browser as soon as I have it and the then the response stream from the server. I noticed that when the response is Chunked if I just read using HTTPWebresponse.GetResponseStream() using a stream reader and forward it to the browser, the browser fails to load the page. After spending some time I realized that GetResponseStream() seems to be already de-chunked, so the browser fails to parse it (since the chunked response header is already sent to the browser which confused it). I made a workaround by removing the chunked header and then sending the responsestream together without chunking.

But I noticed that fiddlercore (royalty-free proxy library) somehow relays the chunked data without doing the workaround I did, it is written in .NET, so I suppose there should be a way to relay the chunks one by one.

My question is how to relay chucked response properly in a proxy when using streams? Also if my proxy is intended for the local machine does the performance would be poor if I sent the data together to the browser without chunking (while proxy uses chunking with the server and vice-versa when requested)?

4

2 回答 2

0

FiddlerCore 是 HTTP/1.1 协议的完整实现,直接编写在 TCP/IP 套接字之上。

因此,它不受高级 WebRequest 类固有的限制(以我必须自己完全实现协议为代价)。

于 2013-09-03T02:10:16.683 回答
0

实际上,每次我从响应流中读入缓冲区时,我都决定再次分块数据(仅当响应标头指示分块响应时)。我想重新分块的性能损失可以忽略不计。如果我只是等待解决方法中提到的所有块被读取,那么我有可能会炸毁可用于代理的内存。

于 2013-09-03T20:51:43.133 回答