Add ability to bind HTTP style headers to stubs and have them propagate over
transports that can deliver them.
This unblocks sending OAuth2 headers natively
-------------
Created by MOE: http://code.google.com/p/moe-java
MOE_MIGRATED_REVID=71118741
diff --git a/core/src/main/java/com/google/net/stubby/http/UrlConnectionClientSession.java b/core/src/main/java/com/google/net/stubby/http/UrlConnectionClientSession.java
index a268228..22794e4 100644
--- a/core/src/main/java/com/google/net/stubby/http/UrlConnectionClientSession.java
+++ b/core/src/main/java/com/google/net/stubby/http/UrlConnectionClientSession.java
@@ -16,6 +16,7 @@
import java.net.HttpURLConnection;
import java.net.URI;
import java.nio.ByteBuffer;
+import java.util.Map;
/**
* Implementation of {@link Session} using {@link HttpURLConnection} for clients. Services
@@ -30,8 +31,9 @@
}
@Override
- public Request startRequest(String operationName, Response.ResponseBuilder responseBuilder) {
- return new Request(base.resolve(operationName), responseBuilder.build());
+ public Request startRequest(String operationName, Map<String, String> headers,
+ Response.ResponseBuilder responseBuilder) {
+ return new Request(base.resolve(operationName), headers, responseBuilder.build());
}
private class Request extends AbstractRequest implements Framer.Sink {
@@ -40,7 +42,7 @@
private final DataOutputStream outputStream;
private final MessageFramer framer;
- private Request(URI uri, Response response) {
+ private Request(URI uri, Map<String, String> headers, Response response) {
super(response);
try {
connection = (HttpURLConnection) uri.toURL().openConnection();
@@ -48,6 +50,9 @@
connection.setDoInput(true);
connection.setRequestMethod("POST");
connection.setRequestProperty("Content-Type", "application/protorpc");
+ for (Map.Entry<String, String> header : headers.entrySet()) {
+ connection.setRequestProperty(header.getKey(), header.getValue());
+ }
outputStream = new DataOutputStream(connection.getOutputStream());
} catch (IOException t) {
throw new RuntimeException(t);