Skip to content

Instantly share code, notes, and snippets.

@kitmenke
Created July 5, 2012 21:35
Show Gist options
  • Save kitmenke/3056620 to your computer and use it in GitHub Desktop.
Save kitmenke/3056620 to your computer and use it in GitHub Desktop.
An example HTTPHandler which will proxy requests to the specified server and allow AJAX development locally.
public class ProxyHandler : IHttpHandler
{
const string SERVER_URL = "http://dev-server";
#region IHttpHandler Members
public bool IsReusable
{
get { return false; }
}
public void ProcessRequest(HttpContext context)
{
HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(SERVER_URL + context.Request.Url.PathAndQuery);
webRequest.Method = context.Request.HttpMethod;
webRequest.Credentials = System.Net.CredentialCache.DefaultNetworkCredentials;
HttpWebResponse response = (HttpWebResponse)webRequest.GetResponse();
context.Response.StatusCode = (int)response.StatusCode;
context.Response.Status = string.Format("{0} {1}", (int)response.StatusCode, response.StatusCode);
context.Response.ContentType = response.ContentType;
context.Response.Write(new StreamReader(response.GetResponseStream()).ReadToEnd());
}
#endregion
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment