c# - TcpListener Proxy HttpWeb -


i'm working on project requires piping http traffic through local proxy, application has set using tcplistener. it's basic setup.

i can standard header, example firefox be:

get http://example.com/ http/1.1 host: example.com user-agent: mozilla/5.0 (windows nt 6.3; wow64; rv:39.0) gecko/20100101 firefox/39.0 accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 accept-language: en-us,en;q=0.5 accept-encoding: gzip, deflate connection: keep-alive 

now, see conctents of example.com though went through proxy. solutions have seen take these headers, , pass them through httpwebrequest. however, don't seem understand how can pass entire header.

if has dealt situation before, or know how can pass entire header httpwebrequest, appreciated.

i'm writing in vb.net way, replies in either of .net languages totally fine.

edit: may have worded little confusing.

what getting request (header) website passing along proxy. read stream tcplistener header. now, stream contains header shown in indented code box. now, in order write response stream containing content shown of no piping done, thinking i'd have take header collected, use httpwebrequest content, write stream, present user intended webpage.

so wondering is: how can feed header httpwebrequest, , content can write networkstream, that'll show normal in browser. how i'd assume proxies work, perhaps not.

http headers separated colon , delimited crlf. header , body separated empty line.

hence continue read tcpclient/socket until receive empty line. parse each header, content-length (to see if should read body too). build httpwebrequest , send everything.

once receive reply need read httpwebresponse, build valid http response message , send back.

you take @ apache licensed library contains httplistener , http encoder/decoder. http://github.com/jgauffin/griffin.framework.


Comments

Popular posts from this blog

c - Bitwise operation with (signed) enum value -

xslt - Unnest parent nodes by child node -

YouTubePlayerFragment cannot be cast to android.support.v4.app.Fragment -