So I am currently writing a custom proxy server to handle http requests on a local computer. I am able to get the headers but am not sure how to then send them to the browser. here is my current source code:
[
Imports System.Net
Imports System.Net.Sockets
Imports System.Text
Imports System.Threading
Imports System.Net.HttpWebRequest
Public Class ProxyServer
Private tcpListener As New TcpListener(IPAddress.Any, 8080)
Private listener As New Thread(AddressOf Listen)
Public Sub Start()
tcpListener.Start()
listener.IsBackground = True
listener.Start()
End Sub
Private Sub Listen()
Dim tcpClient As TcpClient
While True 'Loop And Wait For Connections
Try
'Accept Incomming Connection
tcpClient = tcpListener.AcceptTcpClient()
Dim a As New Thread(AddressOf DoWork)
a.Start(tcpClient)
Catch ex As SocketException
Exit While
End Try
End While
End Sub
Private Sub DoWork(ByVal client As TcpClient)
Dim netStream As NetworkStream = client.GetStream
While True
Try
If netStream.CanRead And netStream.CanWrite Then
Dim bytesToRead(client.ReceiveBufferSize) As Byte
Dim numBytesRead As Integer = netStream.Read(bytesToRead, 0, CInt(client.ReceiveBufferSize))
If numBytesRead < 1 Then Exit While
Dim data As String = Encoding.ASCII.GetString(bytesToRead)
If data.IndexOf(vbNewLine) > -1 Then 'Check To See If Full Command Recieved
'data = this is the whole header
End If
Else
Exit While
End If
Catch ex As IO.IOException
Exit While
End Try
End While
End Sub
End Class
If i configure firefox or IE to the proxy server I do receive the header no problem.
Sample Header
www.google.com
GET http://google.ca/ HTTP/1.1 Accept: image/gif, image/jpeg, image/pjpeg, image/pjpeg, application/x-shockwave-flash, application/x-gsarcade-launch, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, application/xaml+xml, application/vnd.ms-xpsdocument, application/x-ms-xbap, application/x-ms-application, application/x-silverlight, */* Accept-Language: en-us User-Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; .NET CLR 2.0.50727; .NET CLR 3.0.4506.2152; InfoPath.2; .NET CLR 3.5.30729) Accept-Encoding: gzip, deflate Proxy-Connection: Keep-Alive Host: google.ca Cookie: PREF=ID=2cc48986d0a30551:U=4583f9a4276fb2df:FF=0:TM=1297940975:LM=1297941095:S=k0i-eurczYyMJF2q; NID=44=t7EdDRwCJHYI-iYWLo4NeRJ3DtFmv7wZ4yeUmEdemRP7X83I-kRJd6Ah3uf2rw-et_c_H5zYDd7vJuApaX0vs2K_jz30l7uQZPfmTdOeTvKpi67lXrbkiTP2DIOKeYew
My question is how do I send this back to the browser and display the page?
Thanks In Advance.
-Dan