Phase 1 of converting to new Headers mechanism for side-channel.
Introduces Header and uses it for propagating text-only header values over existing transports
Leaves Context & wire format otherwise unchanged
Next phases
- Remove context from interfaces
- Switch the wire format (ESF needs to be done in near lock-step)
Interface changes are relatively light
Headers class is functional but not optimal
All serialization is done as string until transports expose interface for binary headers
-------------
Created by MOE: http://code.google.com/p/moe-java
MOE_MIGRATED_REVID=75050265
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 22794e4..cb32870 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
@@ -2,6 +2,7 @@
import com.google.common.io.ByteBuffers;
import com.google.net.stubby.AbstractRequest;
+import com.google.net.stubby.Metadata;
import com.google.net.stubby.Operation;
import com.google.net.stubby.Response;
import com.google.net.stubby.Session;
@@ -16,7 +17,6 @@
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
@@ -31,9 +31,10 @@
}
@Override
- public Request startRequest(String operationName, Map<String, String> headers,
+ public Request startRequest(String operationName, Metadata.Headers headers,
Response.ResponseBuilder responseBuilder) {
- return new Request(base.resolve(operationName), headers, responseBuilder.build());
+ return new Request(base.resolve(operationName), headers,
+ responseBuilder.build());
}
private class Request extends AbstractRequest implements Framer.Sink {
@@ -42,7 +43,7 @@
private final DataOutputStream outputStream;
private final MessageFramer framer;
- private Request(URI uri, Map<String, String> headers, Response response) {
+ private Request(URI uri, Metadata.Headers headers, Response response) {
super(response);
try {
connection = (HttpURLConnection) uri.toURL().openConnection();
@@ -50,8 +51,11 @@
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());
+ String[] serialized = headers.serializeAscii();
+ for (int i = 0; i < serialized.length; i++) {
+ connection.setRequestProperty(
+ serialized[i],
+ serialized[++i]);
}
outputStream = new DataOutputStream(connection.getOutputStream());
} catch (IOException t) {