Created
February 18, 2016 20:08
-
-
Save ldaley/ad103477882af9c0851d to your computer and use it in GitHub Desktop.
Ratpack authing proxy
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
package com.gradle.receipts.test.browser.util | |
import ratpack.groovy.test.embed.GroovyEmbeddedApp | |
import ratpack.http.client.HttpClient | |
import ratpack.test.ApplicationUnderTest | |
import ratpack.test.CloseableApplicationUnderTest | |
final class AuthingProxy { | |
private AuthingProxy() { | |
} | |
static CloseableApplicationUnderTest admin(ApplicationUnderTest app) { | |
to(app, "admin", "admin") | |
} | |
static CloseableApplicationUnderTest to(ApplicationUnderTest app, String username, String password) { | |
GroovyEmbeddedApp.of { | |
handlers { | |
all { HttpClient httpClient -> | |
def targetUri = new URI(app.address.toASCIIString() + request.rawUri.replaceFirst("/", "")) | |
httpClient.requestStream(targetUri) { | |
it.headers.copy(request.headers) | |
it.basicAuth(username, password) | |
it.redirects(0) | |
} then { | |
it.forwardTo(response) | |
} | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
For reference, I was after something like this:
Unfortunately, I think I now need to work out how to run the proxy over SSL.