Created
October 30, 2013 16:54
-
-
Save lincolnthree/7236099 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @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