HttpHeaders
This commit is contained in:
@@ -82,7 +82,7 @@ public class HttpClusterRpcClient extends HttpRpcClient {
|
||||
String module = req.getRequestURI();
|
||||
module = module.substring(1); //去掉/
|
||||
module = module.substring(0, module.indexOf('/'));
|
||||
HttpHeader headers = req.getHeaders();
|
||||
HttpHeaders headers = req.getHeaders();
|
||||
String resname = req.getHeader(Rest.REST_HEADER_RESNAME, "");
|
||||
final String localModule = module;
|
||||
if (logger.isLoggable(Level.FINEST)) {
|
||||
@@ -96,7 +96,7 @@ public class HttpClusterRpcClient extends HttpRpcClient {
|
||||
}
|
||||
return new HttpResult<byte[]>().status(404).toFuture();
|
||||
}
|
||||
final HttpHeader clientHeaders = HttpHeader.create();
|
||||
final HttpHeaders clientHeaders = HttpHeaders.create();
|
||||
if (headers != null) {
|
||||
boolean ws = headers.contains("Sec-WebSocket-Key");
|
||||
headers.forEach((n, v) -> {
|
||||
@@ -150,7 +150,7 @@ public class HttpClusterRpcClient extends HttpRpcClient {
|
||||
}
|
||||
|
||||
private CompletableFuture<HttpResult<byte[]>> forEachCollectionFuture(final WorkThread workThread, boolean finest, Serializable userid,
|
||||
HttpSimpleRequest req, String requesturi, final HttpHeader clientHeaders, byte[] clientBody, Iterator<InetSocketAddress> it) {
|
||||
HttpSimpleRequest req, String requesturi, final HttpHeaders clientHeaders, byte[] clientBody, Iterator<InetSocketAddress> it) {
|
||||
if (!it.hasNext()) {
|
||||
return CompletableFuture.completedFuture(null);
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ import java.nio.ByteBuffer;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Map;
|
||||
import org.redkale.convert.ConvertType;
|
||||
import org.redkale.net.http.HttpHeader;
|
||||
import org.redkale.net.http.HttpHeaders;
|
||||
import org.redkale.net.http.HttpSimpleRequest;
|
||||
import org.redkale.util.Utility;
|
||||
|
||||
@@ -166,7 +166,7 @@ public class HttpSimpleRequestCoder implements MessageCoder<HttpSimpleRequest> {
|
||||
req.setCurrentUserid(MessageCoder.decodeUserid(buffer));
|
||||
Map<String, Serializable> headerMap = MessageCoder.getSeriMap(buffer);
|
||||
if (Utility.isNotEmpty(headerMap)) {
|
||||
req.setHeaders(HttpHeader.ofValid(headerMap));
|
||||
req.setHeaders(HttpHeaders.ofValid(headerMap));
|
||||
}
|
||||
req.setParams(MessageCoder.getStringMap(buffer));
|
||||
int len = buffer.getInt();
|
||||
|
||||
@@ -25,20 +25,20 @@ import org.redkale.util.RedkaleException;
|
||||
* @author zhangjx
|
||||
* @since 2.8.0
|
||||
*/
|
||||
public class HttpHeader implements RestHeaders, Serializable {
|
||||
public class HttpHeaders implements RestHeaders, Serializable {
|
||||
|
||||
//value值只能是String、List<String>
|
||||
protected LinkedHashMap<String, Serializable> map;
|
||||
|
||||
protected HttpHeader() {
|
||||
protected HttpHeaders() {
|
||||
}
|
||||
|
||||
public static HttpHeader create() {
|
||||
return new HttpHeader();
|
||||
public static HttpHeaders create() {
|
||||
return new HttpHeaders();
|
||||
}
|
||||
|
||||
public static HttpHeader of(String... items) {
|
||||
HttpHeader header = new HttpHeader();
|
||||
public static HttpHeaders of(String... items) {
|
||||
HttpHeaders header = new HttpHeaders();
|
||||
int len = items.length / 2;
|
||||
for (int i = 0; i < len; i++) {
|
||||
header.add(items[i * 2], items[i * 2 + 1]);
|
||||
@@ -51,10 +51,10 @@ public class HttpHeader implements RestHeaders, Serializable {
|
||||
*
|
||||
* @param map 参数
|
||||
*
|
||||
* @return HttpHeader
|
||||
* @return HttpHeaders
|
||||
*/
|
||||
public static HttpHeader ofValid(Map<String, Serializable> map) {
|
||||
HttpHeader header = new HttpHeader();
|
||||
public static HttpHeaders ofValid(Map<String, Serializable> map) {
|
||||
HttpHeaders header = new HttpHeaders();
|
||||
if (map != null) {
|
||||
header.map = map instanceof LinkedHashMap ? (LinkedHashMap) map : new LinkedHashMap(map);
|
||||
}
|
||||
@@ -130,7 +130,7 @@ public class HttpHeader implements RestHeaders, Serializable {
|
||||
return this.map != null && this.map.containsKey(key);
|
||||
}
|
||||
|
||||
public HttpHeader addAll(HttpHeader header) {
|
||||
public HttpHeaders addAll(HttpHeaders header) {
|
||||
if (header.map != null) {
|
||||
if (this.map == null) {
|
||||
this.map = new LinkedHashMap<>(header.map);
|
||||
@@ -141,7 +141,7 @@ public class HttpHeader implements RestHeaders, Serializable {
|
||||
return this;
|
||||
}
|
||||
|
||||
public HttpHeader add(Map<String, String> values) {
|
||||
public HttpHeaders add(Map<String, String> values) {
|
||||
if (values != null) {
|
||||
values.forEach(this::add);
|
||||
}
|
||||
@@ -168,7 +168,7 @@ public class HttpHeader implements RestHeaders, Serializable {
|
||||
}
|
||||
}
|
||||
|
||||
public HttpHeader add(String key, String value) {
|
||||
public HttpHeaders add(String key, String value) {
|
||||
check(key, value);
|
||||
if (this.map == null) {
|
||||
this.map = new LinkedHashMap<>();
|
||||
@@ -189,7 +189,7 @@ public class HttpHeader implements RestHeaders, Serializable {
|
||||
return this;
|
||||
}
|
||||
|
||||
public HttpHeader add(String key, List<String> value) {
|
||||
public HttpHeaders add(String key, List<String> value) {
|
||||
if (value.isEmpty()) {
|
||||
return this;
|
||||
}
|
||||
@@ -215,43 +215,43 @@ public class HttpHeader implements RestHeaders, Serializable {
|
||||
return this;
|
||||
}
|
||||
|
||||
public HttpHeader add(String key, TextConvert convert, Object value) {
|
||||
public HttpHeaders add(String key, TextConvert convert, Object value) {
|
||||
return add(key, (convert == null ? JsonConvert.root() : convert).convertTo(value));
|
||||
}
|
||||
|
||||
public HttpHeader add(String key, Object value) {
|
||||
public HttpHeaders add(String key, Object value) {
|
||||
return add(key, JsonConvert.root().convertTo(value));
|
||||
}
|
||||
|
||||
public HttpHeader add(String key, boolean value) {
|
||||
public HttpHeaders add(String key, boolean value) {
|
||||
return add(key, String.valueOf(value));
|
||||
}
|
||||
|
||||
public HttpHeader add(String key, short value) {
|
||||
public HttpHeaders add(String key, short value) {
|
||||
return add(key, String.valueOf(value));
|
||||
}
|
||||
|
||||
public HttpHeader add(String key, int value) {
|
||||
public HttpHeaders add(String key, int value) {
|
||||
return add(key, String.valueOf(value));
|
||||
}
|
||||
|
||||
public HttpHeader add(String key, float value) {
|
||||
public HttpHeaders add(String key, float value) {
|
||||
return add(key, String.valueOf(value));
|
||||
}
|
||||
|
||||
public HttpHeader add(String key, long value) {
|
||||
public HttpHeaders add(String key, long value) {
|
||||
return add(key, String.valueOf(value));
|
||||
}
|
||||
|
||||
public HttpHeader add(String key, double value) {
|
||||
public HttpHeaders add(String key, double value) {
|
||||
return add(key, String.valueOf(value));
|
||||
}
|
||||
|
||||
public HttpHeader add(String key, BigInteger value) {
|
||||
public HttpHeaders add(String key, BigInteger value) {
|
||||
return add(key, String.valueOf(value));
|
||||
}
|
||||
|
||||
public HttpHeader setAll(HttpHeader header) {
|
||||
public HttpHeaders setAll(HttpHeaders header) {
|
||||
if (header.map != null) {
|
||||
if (this.map == null) {
|
||||
this.map = new LinkedHashMap<>();
|
||||
@@ -261,7 +261,7 @@ public class HttpHeader implements RestHeaders, Serializable {
|
||||
return this;
|
||||
}
|
||||
|
||||
public HttpHeader set(Map<String, String> values) {
|
||||
public HttpHeaders set(Map<String, String> values) {
|
||||
if (values != null) {
|
||||
values.forEach(this::set);
|
||||
}
|
||||
@@ -276,7 +276,7 @@ public class HttpHeader implements RestHeaders, Serializable {
|
||||
this.map.put(key, value);
|
||||
}
|
||||
|
||||
public HttpHeader set(String key, String value) {
|
||||
public HttpHeaders set(String key, String value) {
|
||||
check(key, value);
|
||||
if (this.map == null) {
|
||||
this.map = new LinkedHashMap<>();
|
||||
@@ -285,7 +285,7 @@ public class HttpHeader implements RestHeaders, Serializable {
|
||||
return this;
|
||||
}
|
||||
|
||||
public HttpHeader set(String key, List<String> value) {
|
||||
public HttpHeaders set(String key, List<String> value) {
|
||||
if (value.isEmpty()) {
|
||||
return this;
|
||||
}
|
||||
@@ -299,43 +299,43 @@ public class HttpHeader implements RestHeaders, Serializable {
|
||||
return this;
|
||||
}
|
||||
|
||||
public HttpHeader set(String key, TextConvert convert, Object value) {
|
||||
public HttpHeaders set(String key, TextConvert convert, Object value) {
|
||||
return set(key, (convert == null ? JsonConvert.root() : convert).convertTo(value));
|
||||
}
|
||||
|
||||
public HttpHeader set(String key, Object value) {
|
||||
public HttpHeaders set(String key, Object value) {
|
||||
return set(key, JsonConvert.root().convertTo(value));
|
||||
}
|
||||
|
||||
public HttpHeader set(String key, boolean value) {
|
||||
public HttpHeaders set(String key, boolean value) {
|
||||
return set(key, String.valueOf(value));
|
||||
}
|
||||
|
||||
public HttpHeader set(String key, short value) {
|
||||
public HttpHeaders set(String key, short value) {
|
||||
return set(key, String.valueOf(value));
|
||||
}
|
||||
|
||||
public HttpHeader set(String key, int value) {
|
||||
public HttpHeaders set(String key, int value) {
|
||||
return set(key, String.valueOf(value));
|
||||
}
|
||||
|
||||
public HttpHeader set(String key, float value) {
|
||||
public HttpHeaders set(String key, float value) {
|
||||
return set(key, String.valueOf(value));
|
||||
}
|
||||
|
||||
public HttpHeader set(String key, long value) {
|
||||
public HttpHeaders set(String key, long value) {
|
||||
return set(key, String.valueOf(value));
|
||||
}
|
||||
|
||||
public HttpHeader set(String key, double value) {
|
||||
public HttpHeaders set(String key, double value) {
|
||||
return set(key, String.valueOf(value));
|
||||
}
|
||||
|
||||
public HttpHeader set(String key, BigInteger value) {
|
||||
public HttpHeaders set(String key, BigInteger value) {
|
||||
return set(key, String.valueOf(value));
|
||||
}
|
||||
|
||||
public HttpHeader remove(String key) {
|
||||
public HttpHeaders remove(String key) {
|
||||
if (this.map != null) {
|
||||
this.map.remove(key);
|
||||
}
|
||||
@@ -351,7 +351,7 @@ public class HttpHeader implements RestHeaders, Serializable {
|
||||
return this.map == null || this.map.isEmpty();
|
||||
}
|
||||
|
||||
public HttpHeader clear() {
|
||||
public HttpHeaders clear() {
|
||||
if (this.map != null) {
|
||||
this.map.clear();
|
||||
}
|
||||
@@ -122,7 +122,7 @@ public class HttpRequest extends Request<HttpContext> {
|
||||
|
||||
protected Convert respConvert;
|
||||
|
||||
protected final HttpHeader headers = HttpHeader.create();
|
||||
protected final HttpHeaders headers = HttpHeaders.create();
|
||||
|
||||
//---------- header 相关参数 结束 ----------
|
||||
@Comment("Method GET/POST/...")
|
||||
@@ -2162,7 +2162,7 @@ public class HttpRequest extends Request<HttpContext> {
|
||||
* @return AnyValue
|
||||
*/
|
||||
@AsmDepends
|
||||
public HttpHeader getHeaders() {
|
||||
public HttpHeaders getHeaders() {
|
||||
parseHeader();
|
||||
return headers;
|
||||
}
|
||||
|
||||
@@ -135,23 +135,23 @@ public class HttpSimpleClient extends Client<HttpSimpleConnection, HttpSimpleReq
|
||||
return sendAsync("GET", url, null, body, convert, valueType);
|
||||
}
|
||||
|
||||
public CompletableFuture<HttpResult<byte[]>> getAsync(String url, HttpHeader headers) {
|
||||
public CompletableFuture<HttpResult<byte[]>> getAsync(String url, HttpHeaders headers) {
|
||||
return sendAsync("GET", url, headers, (byte[]) null);
|
||||
}
|
||||
|
||||
public CompletableFuture<HttpResult<byte[]>> getAsync(String url, HttpHeader headers, Type valueType) {
|
||||
public CompletableFuture<HttpResult<byte[]>> getAsync(String url, HttpHeaders headers, Type valueType) {
|
||||
return sendAsync("GET", url, headers, null, (Convert) null, valueType);
|
||||
}
|
||||
|
||||
public CompletableFuture<HttpResult<byte[]>> getAsync(String url, HttpHeader headers, Convert convert, Type valueType) {
|
||||
public CompletableFuture<HttpResult<byte[]>> getAsync(String url, HttpHeaders headers, Convert convert, Type valueType) {
|
||||
return sendAsync("GET", url, headers, null, convert, valueType);
|
||||
}
|
||||
|
||||
public CompletableFuture<HttpResult<byte[]>> getAsync(String url, HttpHeader headers, String body) {
|
||||
public CompletableFuture<HttpResult<byte[]>> getAsync(String url, HttpHeaders headers, String body) {
|
||||
return sendAsync("GET", url, headers, body == null ? null : body.getBytes(StandardCharsets.UTF_8));
|
||||
}
|
||||
|
||||
public CompletableFuture<HttpResult<byte[]>> getAsync(String url, HttpHeader headers, byte[] body) {
|
||||
public CompletableFuture<HttpResult<byte[]>> getAsync(String url, HttpHeaders headers, byte[] body) {
|
||||
return sendAsync("GET", url, headers, body);
|
||||
}
|
||||
|
||||
@@ -191,23 +191,23 @@ public class HttpSimpleClient extends Client<HttpSimpleConnection, HttpSimpleReq
|
||||
return sendAsync("POST", url, null, body, convert, valueType);
|
||||
}
|
||||
|
||||
public CompletableFuture<HttpResult<byte[]>> postAsync(String url, HttpHeader headers) {
|
||||
public CompletableFuture<HttpResult<byte[]>> postAsync(String url, HttpHeaders headers) {
|
||||
return sendAsync("POST", url, headers, (byte[]) null);
|
||||
}
|
||||
|
||||
public CompletableFuture<HttpResult<byte[]>> postAsync(String url, HttpHeader headers, Type valueType) {
|
||||
public CompletableFuture<HttpResult<byte[]>> postAsync(String url, HttpHeaders headers, Type valueType) {
|
||||
return sendAsync("POST", url, headers, null, (Convert) null, valueType);
|
||||
}
|
||||
|
||||
public CompletableFuture<HttpResult<byte[]>> postAsync(String url, HttpHeader headers, Convert convert, Type valueType) {
|
||||
public CompletableFuture<HttpResult<byte[]>> postAsync(String url, HttpHeaders headers, Convert convert, Type valueType) {
|
||||
return sendAsync("POST", url, headers, null, convert, valueType);
|
||||
}
|
||||
|
||||
public CompletableFuture<HttpResult<byte[]>> postAsync(String url, HttpHeader headers, String body) {
|
||||
public CompletableFuture<HttpResult<byte[]>> postAsync(String url, HttpHeaders headers, String body) {
|
||||
return sendAsync("POST", url, headers, body == null ? null : body.getBytes(StandardCharsets.UTF_8));
|
||||
}
|
||||
|
||||
public CompletableFuture<HttpResult<byte[]>> postAsync(String url, HttpHeader headers, byte[] body) {
|
||||
public CompletableFuture<HttpResult<byte[]>> postAsync(String url, HttpHeaders headers, byte[] body) {
|
||||
return sendAsync("POST", url, headers, body);
|
||||
}
|
||||
|
||||
@@ -219,15 +219,15 @@ public class HttpSimpleClient extends Client<HttpSimpleConnection, HttpSimpleReq
|
||||
return sendAsync(req.getMethod(), url, req.getHeaders(), req.getBody(), (Convert) null, null);
|
||||
}
|
||||
|
||||
public CompletableFuture<HttpResult<byte[]>> sendAsync(String method, String url, HttpHeader headers, byte[] body) {
|
||||
public CompletableFuture<HttpResult<byte[]>> sendAsync(String method, String url, HttpHeaders headers, byte[] body) {
|
||||
return sendAsync(method, url, headers, body, (Convert) null, null);
|
||||
}
|
||||
|
||||
public <T> CompletableFuture<HttpResult<T>> sendAsync(String method, String url, HttpHeader headers, byte[] body, Type valueType) {
|
||||
public <T> CompletableFuture<HttpResult<T>> sendAsync(String method, String url, HttpHeaders headers, byte[] body, Type valueType) {
|
||||
return sendAsync(method, url, headers, body, (Convert) null, valueType);
|
||||
}
|
||||
|
||||
public <T> CompletableFuture<HttpResult<T>> sendAsync(String method, String url, HttpHeader headers, byte[] body, Convert convert, Type valueType) {
|
||||
public <T> CompletableFuture<HttpResult<T>> sendAsync(String method, String url, HttpHeaders headers, byte[] body, Convert convert, Type valueType) {
|
||||
final String traceid = Traces.computeIfAbsent(Traces.currentTraceid());
|
||||
final WorkThread workThread = WorkThread.currentWorkThread();
|
||||
if (url.indexOf(' ') >= 0 || url.indexOf('\r') >= 0 || url.indexOf('\n') >= 0) {
|
||||
|
||||
@@ -80,7 +80,7 @@ public class HttpSimpleRequest extends ClientRequest implements java.io.Serializ
|
||||
|
||||
@ConvertColumn(index = 14)
|
||||
@Comment("http header信息")
|
||||
protected HttpHeader headers;
|
||||
protected HttpHeaders headers;
|
||||
|
||||
@ConvertColumn(index = 15)
|
||||
@Comment("参数信息")
|
||||
@@ -103,7 +103,7 @@ public class HttpSimpleRequest extends ClientRequest implements java.io.Serializ
|
||||
return req;
|
||||
}
|
||||
|
||||
public static HttpSimpleRequest create(String requestURI, HttpHeader header) {
|
||||
public static HttpSimpleRequest create(String requestURI, HttpHeaders header) {
|
||||
return new HttpSimpleRequest().requestURI(requestURI).method("POST").headers(header).traceid(Traces.currentTraceid());
|
||||
}
|
||||
|
||||
@@ -231,7 +231,7 @@ public class HttpSimpleRequest extends ClientRequest implements java.io.Serializ
|
||||
return this;
|
||||
}
|
||||
|
||||
public HttpSimpleRequest headers(HttpHeader header) {
|
||||
public HttpSimpleRequest headers(HttpHeaders header) {
|
||||
this.headers = header;
|
||||
return this;
|
||||
}
|
||||
@@ -248,7 +248,7 @@ public class HttpSimpleRequest extends ClientRequest implements java.io.Serializ
|
||||
|
||||
public HttpSimpleRequest addHeader(String key, String value) {
|
||||
if (this.headers == null) {
|
||||
this.headers = HttpHeader.create();
|
||||
this.headers = HttpHeaders.create();
|
||||
}
|
||||
this.headers.add(key, value);
|
||||
return this;
|
||||
@@ -272,7 +272,7 @@ public class HttpSimpleRequest extends ClientRequest implements java.io.Serializ
|
||||
|
||||
public HttpSimpleRequest setHeader(String key, String value) {
|
||||
if (this.headers == null) {
|
||||
this.headers = HttpHeader.create();
|
||||
this.headers = HttpHeaders.create();
|
||||
}
|
||||
this.headers.set(key, value);
|
||||
return this;
|
||||
@@ -450,11 +450,11 @@ public class HttpSimpleRequest extends ClientRequest implements java.io.Serializ
|
||||
this.contentType = contentType;
|
||||
}
|
||||
|
||||
public HttpHeader getHeaders() {
|
||||
public HttpHeaders getHeaders() {
|
||||
return headers;
|
||||
}
|
||||
|
||||
public void setHeaders(HttpHeader headers) {
|
||||
public void setHeaders(HttpHeaders headers) {
|
||||
headers(headers);
|
||||
}
|
||||
|
||||
|
||||
@@ -1102,7 +1102,7 @@ public final class Rest {
|
||||
final String httpResultDesc = Type.getDescriptor(HttpResult.class);
|
||||
final String httpScopeDesc = Type.getDescriptor(HttpScope.class);
|
||||
final String stageDesc = Type.getDescriptor(CompletionStage.class);
|
||||
final String httpHeaderDesc = Type.getDescriptor(HttpHeader.class);
|
||||
final String httpHeaderDesc = Type.getDescriptor(HttpHeaders.class);
|
||||
final String flipperDesc = Type.getDescriptor(Flipper.class);
|
||||
final String httpServletName = HttpServlet.class.getName().replace('.', '/');
|
||||
final String actionEntryName = HttpServlet.ActionEntry.class.getName().replace('.', '/');
|
||||
|
||||
Reference in New Issue
Block a user