You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hc.apache.org by ol...@apache.org on 2021/12/01 16:06:41 UTC
[httpcomponents-core] branch master updated: Refactor HTTP1 Configuration:
This is an automated email from the ASF dual-hosted git repository.
olegk pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/httpcomponents-core.git
The following commit(s) were added to refs/heads/master by this push:
new 0f0597b Refactor HTTP1 Configuration:
0f0597b is described below
commit 0f0597be4975edc6387b64d2cc577f155881e13a
Author: Arturo Bernal <ar...@gmail.com>
AuthorDate: Mon Nov 29 23:00:21 2021 +0100
Refactor HTTP1 Configuration:
* Make WindowSize configurable.
* Check positive value for WindowSize.
* Use constant build();
fix formatting.
---
.../apache/hc/core5/http/config/Http1Config.java | 36 ++++++++++++++--------
1 file changed, 24 insertions(+), 12 deletions(-)
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/http/config/Http1Config.java b/httpcore5/src/main/java/org/apache/hc/core5/http/config/Http1Config.java
index 98c2433..54e26e8 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/http/config/Http1Config.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/http/config/Http1Config.java
@@ -27,6 +27,8 @@
package org.apache.hc.core5.http.config;
+import org.apache.hc.core5.annotation.Contract;
+import org.apache.hc.core5.annotation.ThreadingBehavior;
import org.apache.hc.core5.util.Args;
import org.apache.hc.core5.util.Timeout;
@@ -40,6 +42,7 @@ import org.apache.hc.core5.util.Timeout;
*
* @since 4.3
*/
+@Contract(threading = ThreadingBehavior.IMMUTABLE)
public class Http1Config {
public static final Http1Config DEFAULT = new Builder().build();
@@ -110,7 +113,6 @@ public class Http1Config {
public static Http1Config.Builder custom() {
return new Builder();
}
-
public static Http1Config.Builder copy(final Http1Config config) {
Args.notNull(config, "Config");
return new Builder()
@@ -119,9 +121,18 @@ public class Http1Config {
.setWaitForContinueTimeout(config.getWaitForContinueTimeout())
.setMaxHeaderCount(config.getMaxHeaderCount())
.setMaxLineLength(config.getMaxLineLength())
- .setMaxEmptyLineCount(config.maxEmptyLineCount);
+ .setMaxEmptyLineCount(config.getMaxEmptyLineCount())
+ .setInitialWindowSize(config.getInitialWindowSize());
}
+ private static final int INIT_WINDOW_SIZE = 65535;
+ private static final int INIT_BUF_SIZE = 8192;
+ private static final Timeout INIT_WAIT_FOR_CONTINUE = Timeout.ofSeconds(3);
+ private static final int INIT_BUF_CHUNK = -1;
+ private static final int INIT_MAX_HEADER_COUNT = -1;
+ private static final int INIT_MAX_LINE_LENGTH = -1;
+ private static final int INIT_MAX_EMPTY_LINE_COUNT = 10;
+
public static class Builder {
private int bufferSize;
@@ -133,13 +144,13 @@ public class Http1Config {
private int initialWindowSize;
Builder() {
- this.bufferSize = -1;
- this.chunkSizeHint = -1;
- this.waitForContinueTimeout = Timeout.ofSeconds(3);
- this.maxLineLength = -1;
- this.maxHeaderCount = -1;
- this.maxEmptyLineCount = 10;
- this.initialWindowSize = -1;
+ this.bufferSize = INIT_BUF_SIZE;
+ this.chunkSizeHint = INIT_BUF_CHUNK;
+ this.waitForContinueTimeout = INIT_WAIT_FOR_CONTINUE;
+ this.maxLineLength = INIT_MAX_LINE_LENGTH;
+ this.maxHeaderCount = INIT_MAX_HEADER_COUNT;
+ this.maxEmptyLineCount = INIT_MAX_EMPTY_LINE_COUNT;
+ this.initialWindowSize = INIT_WINDOW_SIZE;
}
public Builder setBufferSize(final int bufferSize) {
@@ -173,19 +184,20 @@ public class Http1Config {
}
public Builder setInitialWindowSize(final int initialWindowSize) {
+ Args.positive(initialWindowSize, "Initial window size");
this.initialWindowSize = initialWindowSize;
return this;
}
public Http1Config build() {
return new Http1Config(
- bufferSize > 0 ? bufferSize : 8192,
+ bufferSize,
chunkSizeHint,
- waitForContinueTimeout != null ? waitForContinueTimeout : Timeout.ofSeconds(3),
+ waitForContinueTimeout,
maxLineLength,
maxHeaderCount,
maxEmptyLineCount,
- initialWindowSize > 0 ? initialWindowSize : 65535);
+ initialWindowSize);
}
}