This is an automated email from the ASF dual-hosted git repository.

ningjiang pushed a commit to branch master
in repository 
https://gitbox.apache.org/repos/asf/incubator-servicecomb-java-chassis.git

commit 0a69db52db54b6a44daded18938cea290238b341
Author: jeho0815 <jeho0...@email.com>
AuthorDate: Tue Feb 13 09:30:05 2018 +0800

    [SCB-314] Support custom rest transport server compress and max header size
---
 .../apache/servicecomb/demo/springmvc/client/SpringmvcClient.java  | 7 +++++--
 .../springmvc-client/src/main/resources/microservice.yaml          | 5 ++++-
 .../servicecomb/transport/rest/client/RestTransportClient.java     | 1 +
 .../servicecomb/transport/rest/client/TransportClientConfig.java   | 4 ++++
 .../transport/rest/client/TestTransportClientConfig.java           | 5 +++++
 5 files changed, 19 insertions(+), 3 deletions(-)

diff --git 
a/demo/demo-springmvc/springmvc-client/src/main/java/org/apache/servicecomb/demo/springmvc/client/SpringmvcClient.java
 
b/demo/demo-springmvc/springmvc-client/src/main/java/org/apache/servicecomb/demo/springmvc/client/SpringmvcClient.java
index b3e0f85..c49fc05 100644
--- 
a/demo/demo-springmvc/springmvc-client/src/main/java/org/apache/servicecomb/demo/springmvc/client/SpringmvcClient.java
+++ 
b/demo/demo-springmvc/springmvc-client/src/main/java/org/apache/servicecomb/demo/springmvc/client/SpringmvcClient.java
@@ -95,8 +95,11 @@ public class SpringmvcClient {
     TestMgr.check(
         "Test sayhi compressed:This is a big text,This is a big text,This is a 
big text,This is a big text,This is a big text,This is a big text,This is a big 
text,This is a big text,This is a big text,This is a big text,This is a big 
text,This is a big text,This is a big text,This is a big text,This is a big 
text,This is a big text,This is a big text,This is a big text,This is a big 
text,This is a big text,This is a big text,This is a big text,This is a big 
text,This is a big text,This  [...]
         entityCompress.getBody());
-    TestMgr.check("gzip", entityCompress.getHeaders().get("content-encoding"));
-    TestMgr.check("75", entityCompress.getHeaders().get("content-length"));
+    // if server response is compressed, the content-length header will be 
removed , so can't check this.
+    // the transfer-encoding header will be missing when the server is setted 
to not compressed
+    if (entityCompress.getHeaders().get("transfer-encoding") != null) {
+      TestMgr.check("chunked", 
entityCompress.getHeaders().get("transfer-encoding").get(0));
+    }
 
     //0.5.0 later version metrics integration test
     try {
diff --git 
a/demo/demo-springmvc/springmvc-client/src/main/resources/microservice.yaml 
b/demo/demo-springmvc/springmvc-client/src/main/resources/microservice.yaml
index 13cc606..72d65bf 100644
--- a/demo/demo-springmvc/springmvc-client/src/main/resources/microservice.yaml
+++ b/demo/demo-springmvc/springmvc-client/src/main/resources/microservice.yaml
@@ -35,7 +35,10 @@ cse:
           interval: 90
         watch: false
       autodiscovery: true
-
+  rest:
+    client:
+      connection:
+        compression: true
   references:
     version-rule: 0+
   handler:
diff --git 
a/transports/transport-rest/transport-rest-client/src/main/java/org/apache/servicecomb/transport/rest/client/RestTransportClient.java
 
b/transports/transport-rest/transport-rest-client/src/main/java/org/apache/servicecomb/transport/rest/client/RestTransportClient.java
index b326a09..1fed065 100644
--- 
a/transports/transport-rest/transport-rest-client/src/main/java/org/apache/servicecomb/transport/rest/client/RestTransportClient.java
+++ 
b/transports/transport-rest/transport-rest-client/src/main/java/org/apache/servicecomb/transport/rest/client/RestTransportClient.java
@@ -55,6 +55,7 @@ public final class RestTransportClient {
     
httpClientOptions.setMaxPoolSize(TransportClientConfig.getConnectionMaxPoolSize());
     
httpClientOptions.setIdleTimeout(TransportClientConfig.getConnectionIdleTimeoutInSeconds());
     
httpClientOptions.setKeepAlive(TransportClientConfig.getConnectionKeepAlive());
+    
httpClientOptions.setTryUseCompression(TransportClientConfig.getConnectionCompression());
 
     VertxTLSBuilder.buildHttpClientOptions(SSL_KEY, httpClientOptions);
     return httpClientOptions;
diff --git 
a/transports/transport-rest/transport-rest-client/src/main/java/org/apache/servicecomb/transport/rest/client/TransportClientConfig.java
 
b/transports/transport-rest/transport-rest-client/src/main/java/org/apache/servicecomb/transport/rest/client/TransportClientConfig.java
index f46d9b0..9803267 100644
--- 
a/transports/transport-rest/transport-rest-client/src/main/java/org/apache/servicecomb/transport/rest/client/TransportClientConfig.java
+++ 
b/transports/transport-rest/transport-rest-client/src/main/java/org/apache/servicecomb/transport/rest/client/TransportClientConfig.java
@@ -40,4 +40,8 @@ public final class TransportClientConfig {
   public static boolean getConnectionKeepAlive() {
     return 
DynamicPropertyFactory.getInstance().getBooleanProperty("cse.rest.client.connection.keepAlive",
 true).get();
   }
+  
+  public static boolean getConnectionCompression() {
+    return 
DynamicPropertyFactory.getInstance().getBooleanProperty("cse.rest.client.connection.compression",
 false).get();
+  }
 }
diff --git 
a/transports/transport-rest/transport-rest-client/src/test/java/org/apache/servicecomb/transport/rest/client/TestTransportClientConfig.java
 
b/transports/transport-rest/transport-rest-client/src/test/java/org/apache/servicecomb/transport/rest/client/TestTransportClientConfig.java
index 343d64d..bbc2e75 100644
--- 
a/transports/transport-rest/transport-rest-client/src/test/java/org/apache/servicecomb/transport/rest/client/TestTransportClientConfig.java
+++ 
b/transports/transport-rest/transport-rest-client/src/test/java/org/apache/servicecomb/transport/rest/client/TestTransportClientConfig.java
@@ -40,4 +40,9 @@ public class TestTransportClientConfig {
   public void getConnectionKeepAlive() {
     Assert.assertTrue(TransportClientConfig.getConnectionKeepAlive());
   }
+
+  @Test
+  public void getConnectionCompression() {
+    Assert.assertFalse(TransportClientConfig.getConnectionCompression());
+  }
 }

-- 
To stop receiving notification emails like this one, please contact
ningji...@apache.org.

Reply via email to