1: Imports System
2: Imports System.Web
3: Imports System.Net
4: Imports System.IO
5:
6: Public Class GoogleSecureGraphs
7: Implements IHttpHandler
8:
9: Public ReadOnly Property IsReusable() As Boolean Implements System.Web.IHttpHandler.IsReusable
10: Get
11: Return False
12: End Get
13: End Property
14:
15: Public Sub ProcessRequest(ByVal context As System.Web.HttpContext) Implements System.Web.IHttpHandler.ProcessRequest
16:
17: Const BufferLength As Integer = 1000
18: Const Chartx As String = "http://chart.apis.google.com/chart?"
19: If (context Is Nothing) Then
20: Throw New ArgumentNullException("context")
21: End If
22:
23: If Not IsNothing(context.Request.QueryString) Then
24: Dim xURL As String = Null.NullString
25:
26: xURL = context.Request.RawUrl.Substring(context.Request.RawUrl.IndexOf("?") + 1)
27:
28: Dim MyRequest As HttpWebRequest = CType(WebRequest.Create(Chartx & xURL), HttpWebRequest)
29: MyRequest.Timeout = 10 * 1000
30:
31: ' Get the web response
32: Dim MyResponse As HttpWebResponse = CType(MyRequest.GetResponse(), HttpWebResponse)
33: Dim s As Stream = MyResponse.GetResponseStream
34:
35: ' Make sure the response is valid
36: If HttpStatusCode.OK = MyResponse.StatusCode Then
37:
38: Dim ms As MemoryStream = New MemoryStream(MyResponse.ContentLength)
39: Dim b As Byte() = New Byte(BufferLength) {}
40: Dim cnt As Integer = 0
41:
42: Do
43:
44: cnt = s.Read(b, 0, BufferLength)
45: ms.Write(b, 0, cnt)
46:
47: Loop Until cnt < 1
48:
49: context.Response.ContentType = MyResponse.ContentType
50: context.Response.Cache.SetCacheability(HttpCacheability.NoCache)
51:
52: context.Response.BinaryWrite(ms.ToArray)
53: MyResponse.Close()
54:
55: End If
56: End If
57:
58: context.Response.End()
59:
60:
61: End Sub
62:
63: End Class