[ 
https://issues.apache.org/jira/browse/SCB-897?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16606662#comment-16606662
 ] 

ASF GitHub Bot commented on SCB-897:
------------------------------------

liubao68 closed pull request #895: [SCB-897] Support max initial line length 
config
URL: https://github.com/apache/incubator-servicecomb-java-chassis/pull/895
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git 
a/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/ConsumerMain.java
 
b/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/ConsumerMain.java
index 023a71993..a3b770471 100644
--- 
a/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/ConsumerMain.java
+++ 
b/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/ConsumerMain.java
@@ -27,6 +27,8 @@
 import org.apache.servicecomb.it.testcase.TestParamCodec;
 import org.apache.servicecomb.it.testcase.TestTrace;
 import org.apache.servicecomb.it.testcase.TestTraceEdge;
+import org.apache.servicecomb.it.testcase.base.TestParamCodecEdge;
+import org.apache.servicecomb.it.testcase.base.TestRestServerConfig;
 
 public class ConsumerMain {
   private static ResultPrinter resultPrinter = new ResultPrinter();
@@ -110,6 +112,9 @@ private static void testStandalone() throws Throwable {
     ITJUnitUtils.run(TestTraceEdge.class);
 
     ITJUnitUtils.runWithHighwayAndRest(TestParamCodec.class);
+    ITJUnitUtils.run(TestParamCodecEdge.class);
+
+    ITJUnitUtils.runWithRest(TestRestServerConfig.class);
 
     ITJUnitUtils.getParents().pop();
     deploys.getBaseProducer().stop();
diff --git 
a/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/testcase/base/TestParamCodecEdge.java
 
b/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/testcase/base/TestParamCodecEdge.java
new file mode 100644
index 000000000..2ca171af3
--- /dev/null
+++ 
b/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/testcase/base/TestParamCodecEdge.java
@@ -0,0 +1,35 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.servicecomb.it.testcase.base;
+
+import static org.junit.Assert.assertEquals;
+
+import org.apache.servicecomb.it.extend.engine.GateRestTemplate;
+import org.junit.Test;
+import org.springframework.web.client.RestTemplate;
+
+public class TestParamCodecEdge {
+  static RestTemplate rt = 
GateRestTemplate.createEdgeRestTemplate("paramCodec");
+
+  @Test
+  public void spaceCharEncode() {
+    String paramString = "a%2B+%20b%% %20c";
+    String result = rt.getForObject("/spaceCharCodec/" + paramString + "?q=" + 
paramString, String.class);
+    assertEquals(paramString + " +%20%% " + paramString + " true", result);
+  }
+}
diff --git 
a/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/testcase/base/TestRestServerConfig.java
 
b/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/testcase/base/TestRestServerConfig.java
new file mode 100644
index 000000000..6192c7ee0
--- /dev/null
+++ 
b/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/testcase/base/TestRestServerConfig.java
@@ -0,0 +1,67 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.servicecomb.it.testcase.base;
+
+import org.apache.servicecomb.it.Consumers;
+import org.apache.servicecomb.it.junit.ITJUnitUtils;
+import org.apache.servicecomb.swagger.invocation.exception.InvocationException;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import com.google.common.base.Strings;
+
+public class TestRestServerConfig {
+  // GET /v1/restServerConfig/testMaxInitialLineLength?q=...... HTTP/1.1
+  private static final String INITIAL_LINE_SUFFIX = " HTTP/1.1";
+
+  private static final String INITIAL_LINE_PREFIX = "GET 
/v1/restServerConfig/testMaxInitialLineLength?q=";
+
+  interface RestServerConfigSchemaIntf {
+    String testMaxInitialLineLength(String q);
+  }
+
+  static Consumers<RestServerConfigSchemaIntf> consumers = new 
Consumers<>("restServerConfig",
+      RestServerConfigSchemaIntf.class);
+
+  @BeforeClass
+  public static void classSetup() {
+    consumers.init(ITJUnitUtils.getTransport());
+  }
+
+  /**
+   * Max initial line length is set to 5000
+   */
+  @Test
+  public void testMaxInitialLineLength5000() {
+    String q = Strings.repeat("q", 5000 - INITIAL_LINE_PREFIX.length() - 
INITIAL_LINE_SUFFIX.length());
+    String result = consumers.getIntf().testMaxInitialLineLength(q);
+    Assert.assertEquals("OK", result);
+  }
+
+  @Test
+  public void testMaxInitialLineLength5001() {
+    String q = Strings.repeat("q", 5001 - INITIAL_LINE_PREFIX.length() - 
INITIAL_LINE_SUFFIX.length());
+    try {
+      consumers.getIntf().testMaxInitialLineLength(q.toString());
+      Assert.fail("an exception is expected!");
+    } catch (InvocationException e) {
+      Assert.assertEquals(414, e.getStatusCode());
+    }
+  }
+}
diff --git 
a/integration-tests/it-producer/src/main/java/org/apache/servicecomb/it/schema/RestServerConfigSchema.java
 
b/integration-tests/it-producer/src/main/java/org/apache/servicecomb/it/schema/RestServerConfigSchema.java
new file mode 100644
index 000000000..d8a3dac9a
--- /dev/null
+++ 
b/integration-tests/it-producer/src/main/java/org/apache/servicecomb/it/schema/RestServerConfigSchema.java
@@ -0,0 +1,34 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.servicecomb.it.schema;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.QueryParam;
+
+import org.apache.servicecomb.provider.rest.common.RestSchema;
+
+@RestSchema(schemaId = "restServerConfig")
+@Path("/v1/restServerConfig")
+public class RestServerConfigSchema {
+  @Path("/testMaxInitialLineLength")
+  @GET
+  public String testMaxInitialLineLength(@QueryParam("q") String q) {
+    return "OK";
+  }
+}
diff --git a/integration-tests/it-producer/src/main/resources/microservice.yaml 
b/integration-tests/it-producer/src/main/resources/microservice.yaml
index 102722d8c..2621253ea 100644
--- a/integration-tests/it-producer/src/main/resources/microservice.yaml
+++ b/integration-tests/it-producer/src/main/resources/microservice.yaml
@@ -18,3 +18,7 @@
 service_description:
   name: it-producer
 
+servicecomb:
+  rest:
+    server:
+      maxInitialLineLength: 5000
\ No newline at end of file
diff --git 
a/transports/transport-rest/transport-rest-vertx/src/main/java/org/apache/servicecomb/transport/rest/vertx/RestServerVerticle.java
 
b/transports/transport-rest/transport-rest-vertx/src/main/java/org/apache/servicecomb/transport/rest/vertx/RestServerVerticle.java
index 53c3890ee..757f44d75 100644
--- 
a/transports/transport-rest/transport-rest-vertx/src/main/java/org/apache/servicecomb/transport/rest/vertx/RestServerVerticle.java
+++ 
b/transports/transport-rest/transport-rest-vertx/src/main/java/org/apache/servicecomb/transport/rest/vertx/RestServerVerticle.java
@@ -200,6 +200,7 @@ private HttpServerOptions createDefaultHttpServerOptions() {
     
serverOptions.setIdleTimeout(TransportConfig.getConnectionIdleTimeoutInSeconds());
     serverOptions.setCompressionSupported(TransportConfig.getCompressed());
     serverOptions.setMaxHeaderSize(TransportConfig.getMaxHeaderSize());
+    
serverOptions.setMaxInitialLineLength(TransportConfig.getMaxInitialLineLength());
     if (endpointObject.isHttp2Enabled()) {
       serverOptions.setUseAlpn(true);
     }
diff --git 
a/transports/transport-rest/transport-rest-vertx/src/main/java/org/apache/servicecomb/transport/rest/vertx/TransportConfig.java
 
b/transports/transport-rest/transport-rest-vertx/src/main/java/org/apache/servicecomb/transport/rest/vertx/TransportConfig.java
index ed784a8e2..206472252 100644
--- 
a/transports/transport-rest/transport-rest-vertx/src/main/java/org/apache/servicecomb/transport/rest/vertx/TransportConfig.java
+++ 
b/transports/transport-rest/transport-rest-vertx/src/main/java/org/apache/servicecomb/transport/rest/vertx/TransportConfig.java
@@ -28,6 +28,7 @@
 import com.netflix.config.DynamicStringProperty;
 
 import io.vertx.core.Verticle;
+import io.vertx.core.http.HttpServerOptions;
 
 public final class TransportConfig {
 
@@ -141,4 +142,11 @@ public static int getCorsMaxAge() {
     }
     return resultSet;
   }
+
+  public static int getMaxInitialLineLength() {
+    return DynamicPropertyFactory.getInstance()
+        .getIntProperty("servicecomb.rest.server.maxInitialLineLength",
+            HttpServerOptions.DEFAULT_MAX_INITIAL_LINE_LENGTH)
+        .get();
+  }
 }
diff --git 
a/transports/transport-rest/transport-rest-vertx/src/test/java/org/apache/servicecomb/transport/rest/vertx/TestTransportConfig.java
 
b/transports/transport-rest/transport-rest-vertx/src/test/java/org/apache/servicecomb/transport/rest/vertx/TestTransportConfig.java
index 7b6372eac..bca09be70 100644
--- 
a/transports/transport-rest/transport-rest-vertx/src/test/java/org/apache/servicecomb/transport/rest/vertx/TestTransportConfig.java
+++ 
b/transports/transport-rest/transport-rest-vertx/src/test/java/org/apache/servicecomb/transport/rest/vertx/TestTransportConfig.java
@@ -140,4 +140,11 @@ public void testGetCorsMaxAge() {
     ArchaiusUtils.setProperty("servicecomb.cors.maxAge", 3600);
     Assert.assertEquals(3600, TransportConfig.getCorsMaxAge());
   }
+
+  @Test
+  public void testGetMaxInitialLineLength() {
+    Assert.assertEquals(4096, TransportConfig.getMaxInitialLineLength());
+    ArchaiusUtils.setProperty("servicecomb.rest.server.maxInitialLineLength", 
8000);
+    Assert.assertEquals(8000, TransportConfig.getMaxInitialLineLength());
+  }
 }


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


> Support config rest server max initial line length
> --------------------------------------------------
>
>                 Key: SCB-897
>                 URL: https://issues.apache.org/jira/browse/SCB-897
>             Project: Apache ServiceComb
>          Issue Type: Improvement
>            Reporter: YaoHaishi
>            Assignee: YaoHaishi
>            Priority: Major
>
> Currently the http request first line length is limited to 4096 on provider 
> side.
> We need to provide a config item for user to specify it.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to