Skip to content

Instantly share code, notes, and snippets.

@mahizsas
Forked from kitmenke/ProxyHandler.cs
Last active August 29, 2015 14:13
Show Gist options
  • Save mahizsas/d298c48cd65ccc7882d3 to your computer and use it in GitHub Desktop.
Save mahizsas/d298c48cd65ccc7882d3 to your computer and use it in GitHub Desktop.
HttpHandler that act as a proxy
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