Permalink
Browse files

[cap-backend] Refactor D2 transportClientProperties in to common prop…

…erty and add http.protocolVersion to allowedClientOverrideKeys

RB=1109051
G=si-core-reviewers
R=tkhemka
A=tkhemka,dhoa,fcapponi
  • Loading branch information...
ssheng committed Sep 26, 2017
1 parent da68080 commit a79cf45f6fbcd4e22f542afa5f57494abf8aac5e
View
@@ -1,6 +1,7 @@
15.0.4
-------
(RB=1109051)
Expose remote port number in the request context in both server and client sides
15.0.3
-------
@@ -25,18 +25,20 @@
public static final String OPERATION = "OPERATION";
/**
* The address of the remote client or last proxy that sent the http request.
* Typically this value is set by servlets and accessible
* for server side code
* */
* The address and port of the remote client or last proxy that sent the http request.
* Typically this value is set by servlets and accessible for server side code.
**/
public static final String REMOTE_ADDR = "REMOTE_ADDR";
public static final String REMOTE_PORT = "REMOTE_PORT";
/**
* The address of the remote server that received the http request.
* The address and port of the remote server that received the http request.
* Typically this value is set by transport client and accessible for
* client side code after the request is sent
* */
public static final String REMOTE_SERVER_ADDR = "REMOTE_SERVER_ADDR";
public static final String REMOTE_SERVER_PORT = "REMOTE_SERVER_PORT";
/**
* The HTTP protocol that the client and server are communicated under.
@@ -212,7 +212,7 @@ protected RestRequest readFromServletRequest(HttpServletRequest req) throws IOEx
}
}
}
int length = req.getContentLength();
if (length > 0)
{
@@ -239,6 +239,7 @@ protected RequestContext readRequestContext(HttpServletRequest req)
{
RequestContext context = new RequestContext();
context.putLocalAttr(R2Constants.REMOTE_ADDR, req.getRemoteAddr());
context.putLocalAttr(R2Constants.REMOTE_PORT, req.getRemotePort());
HttpProtocolVersion protocol = HttpProtocolVersion.parse(req.getProtocol());
context.putLocalAttr(R2Constants.HTTP_PROTOCOL_VERSION, protocol);
@@ -164,6 +164,7 @@ static RequestContext readRequestContext(HttpServletRequest req)
{
RequestContext context = new RequestContext();
context.putLocalAttr(R2Constants.REMOTE_ADDR, req.getRemoteAddr());
context.putLocalAttr(R2Constants.REMOTE_PORT, req.getRemotePort());
HttpProtocolVersion protocol = HttpProtocolVersion.parse(req.getProtocol());
context.putLocalAttr(R2Constants.HTTP_PROTOCOL_VERSION, protocol);
@@ -262,6 +262,7 @@ private SocketAddress resolveAddress(Req request, RequestContext requestContext)
InetAddress inetAddress = InetAddress.getByName(host);
final SocketAddress address = new InetSocketAddress(inetAddress, port);
requestContext.putLocalAttr(R2Constants.REMOTE_SERVER_ADDR, inetAddress.getHostAddress());
requestContext.putLocalAttr(R2Constants.REMOTE_SERVER_PORT, port);
return address;
}
@@ -197,11 +197,13 @@ public void testRequestContextAttributes()
client.restRequest(r, requestContext, new HashMap<>(), callback);
final String actualRemoteAddress = (String) requestContext.getLocalAttr(R2Constants.REMOTE_SERVER_ADDR);
final int actualRemotePort = (int) requestContext.getLocalAttr(R2Constants.REMOTE_SERVER_PORT);
final HttpProtocolVersion actualProtocolVersion = (HttpProtocolVersion) requestContext.getLocalAttr(R2Constants.HTTP_PROTOCOL_VERSION);
Assert.assertTrue("127.0.0.1".equals(actualRemoteAddress) || "0:0:0:0:0:0:0:1".equals(actualRemoteAddress),
"Actual remote client address is not expected. " +
"The local attribute field must be IP address in string type");
Assert.assertEquals(actualRemotePort, 80);
Assert.assertEquals(actualProtocolVersion, HttpProtocolVersion.HTTP_1_1);
}

0 comments on commit a79cf45

Please sign in to comment.