pastebin - collaborative debugging

pastebin is a collaborative debugging tool allowing you to share and modify code snippets while chatting on IRC, IM or a message board.

This site is developed to XHTML and CSS2 W3C standards. If you see this paragraph, your browser does not support those standards and you need to upgrade. Visit WaSP for a variety of options.

VB.NET pastebin - collaborative debugging tool View Help


Posted by juneof44 on Sat 4 Apr 08:31
report abuse | View followups from reddit | download | new post

  1. <%@ WebHandler Language="VB" Class="imgur" %>
  2.  
  3. Imports System
  4. Imports System.Web
  5. Imports System.Net
  6. Imports System.IO
  7.  
  8. Public Class imgur : Implements IHttpHandler
  9.    
  10.     Public Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest
  11.         If context.Request.QueryString.Count = 0 Then Exit Sub
  12.        
  13.         Dim remoteWebSite As String = "http://imgur.com/"
  14.         Dim imageName = context.Request.QueryString(0)
  15.  
  16.                
  17.         If Not Regex.IsMatch(imageName, "(.*?)\.(jpg|jpeg|png|gif)$", RegexOptions.IgnoreCase) Then
  18.             context.Response.Write("<h2>doesn't look like an image to me :(</h2>")
  19.             context.Response.End()
  20.             Return
  21.         End If
  22.        
  23.                                    
  24.         Dim request = WebRequest.Create(remoteWebSite & imageName)
  25.         Dim response As HttpWebResponse
  26.            
  27.         Try
  28.             response = request.GetResponse
  29.         Catch ex As WebException
  30.             context.Response.Write("<h2>Image not found</h2>")
  31.             context.Response.End()
  32.             Return
  33.         End Try
  34.  
  35.         If response.ContentType = "text/html" Then
  36.             context.Response.Write("<h2>Image not found</h2>")
  37.             context.Response.End()
  38.             Return
  39.         End If
  40.        
  41.        
  42.        
  43.         Using recieveStream = response.GetResponseStream
  44.  
  45.             Dim length = 256
  46.             Dim buffer = New Byte(length) {}
  47.             Dim bytesRead = recieveStream.Read(buffer, 0, length)
  48.                    
  49.             While bytesRead > 0
  50.                 context.Response.OutputStream.Write(buffer, 0, bytesRead)
  51.                 bytesRead = recieveStream.Read(buffer, 0, length)
  52.             End While
  53.                
  54.         End Using
  55.  
  56.        
  57.         context.Response.ContentType = response.ContentType
  58.         response.Close()
  59.         context.Response.End()
  60.        
  61.  
  62.     End Sub
  63.  
  64.     Public ReadOnly Property IsReusable() As Boolean Implements IHttpHandler.IsReusable
  65.         Get
  66.             Return False
  67.         End Get
  68.     End Property
  69.  
  70. End Class

Submit a correction or amendment below (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.

Syntax highlighting:

To highlight particular lines, prefix each line with @@


Remember me so that I can delete my post