Skip to content

Instantly share code, notes, and snippets.

@lincolnthree
Created October 30, 2013 16:54
Show Gist options
  • Select an option

  • Save lincolnthree/7236099 to your computer and use it in GitHub Desktop.

Select an option

Save lincolnthree/7236099 to your computer and use it in GitHub Desktop.
@Override
public Configuration getConfiguration(ServletContext context)
{
return ConfigurationBuilder
.begin()
.addRule()
.when(PathAndQuery.matches("/api/{url}").and(Query.parameterExists("repo")
.and(Query.parameterExists("key"))))
/*
* Subset used to eliminate database overhead.
*/
.perform(Subset.evaluate(ConfigurationBuilder.begin()
.addRule()
.when(new Condition()
{
@Override
public boolean evaluate(Rewrite event, EvaluationContext context)
{
QueryStringBuilder query = QueryStringBuilder.createNew().addParameters(
((HttpServletRewrite) event).getAddress().getQuery());
String repoUrl = query.getParameter("repo");
String key = query.getParameter("key");
return controller.isRepositoryApiKey(repoUrl, key);
}
})
.perform(new Operation()
{
@Override
public void perform(Rewrite event, EvaluationContext context)
{
String contextPath = ((HttpServletRewrite) event).getServletContext().getContextPath();
String url = ((HttpServletRewrite) event).getAddress().getPathAndQuery()
.replaceFirst(contextPath + "/api", "");
Proxy.to(settings.getRedoculousURL()
+ url + "&nogzip").perform(event, context);
}
})));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment