exyus as an HTTP proxy
i added a high-level function to the exyus engine this evening that makes it easy to publish a resource that makes a call to a remote HTTP server and displays the results. basically, it's a (very) simple HTTP proxy. below is an example of the resource class definition:
// simple direct get handler
[UriPattern(@"/remote/(\.xcs)(.*)?")]
[MediaTypes("text/html")]
public class remotePage : StaticHandler
{
public remotePage()
{
this.Content = Helper.LoadUrl("http://www.amundsen.com/blog/");
}
}
the code behind the Helper.LoadUrl method is pretty simple, too. it takes advantage of the Requestor class in exyus:
public static string LoadUrl(string url)
{
return LoadUrl(url, "text/html");
}
public static string LoadUrl(string url, string contenttype)
{
string rtn = string.Empty;
Requestor req = new Requestor();
rtn = req.Execute(url, "get", contenttype);
req = null;
return rtn;
}
there are a number of things that could be done to make the LoadUrl method a bit more robust. things like adding support for headers, credentials, a bit of error handling, etc. all this is available in the Requestor class - just not exposed here. but the point is, this kind of thing is pretty easy.