title: How to pass through http call with HTTP Handler
body: <p><strong>Background:</strong></p>
  
  <p>We are using the Facebook API and receive back URLs for profile image thumbnails. Unfortunately the protocol is restricted to just HTTP and it doesn't support HTTPS. The page on our site that hosts the thumbnails is always delivered via HTTPS, and if we use HTTP for the thumbnails the user will receive security warnings from their browser.</p>
  
  <p><strong>Solution:</strong></p>
  
  <p>Build an HTTP Handler that "passes through" the image from the Facebook URL, but allow the handler to be called via HTTPS. Before I started coding I thought I could something like this:</p>
  
  <pre><code>Response.OutputStream = WebRequest.Create(FacebookUrlForThumbnail)
  </code></pre>
  
  <p>but I ended up having to save the image to an object in memory than write the image to the Response.OutputStream using the image save function. </p>
  
  <p><strong>Current Code:</strong></p>
  
  <pre><code>Public Class FBImageHttpHandler
      Implements System.Web.IHttpHandler
  
      Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest
          Dim profilePath As String = context.Request.QueryString("profilepath")
          Dim request As WebRequest = Nothing
          Dim image As System.Drawing.Bitmap = Nothing
          Dim errorMessage As String
          Dim profileDomain As String
  
          Try
              profileDomain = "http://[Facebook-Image-Domain].com/"
  
              If profilePath.ToLower.EndsWith(".jpg") = True Then
                  request = WebRequest.Create(profileDomain &amp; profilePath)
  
                  If (request.GetResponse().ContentLength &gt; 0) Then
                      context.Response.ContentType = "image/jpeg"
  
                      image = New System.Drawing.Bitmap(request.GetResponse().GetResponseStream())
                      image.Save(context.Response.OutputStream, System.Drawing.Imaging.ImageFormat.Jpeg)
                  End If
              End If
          Catch ex As Exception
              ' Ignore Error
              ' Log Error - Removed Logging Code   
          Finally
              If request IsNot Nothing Then
                  request = Nothing
              End If
  
              If image IsNot Nothing Then
                  image.Dispose()
                  image = Nothing
              End If
          End Try
      End Sub
  
      ReadOnly Property IsReusable() As Boolean Implements IHttpHandler.IsReusable
          Get
              Return False
          End Get
      End Property
  
  End Class
  </code></pre>
  
  <p>This seems inefficient but I can't find a way of using the HTTP Handler as I orginally intended. Is there way of accomplishing the goal without creating the image memory and just "passing through" the call?</p>