增加HttpHeader

This commit is contained in:
redkale
2023-11-20 18:17:48 +08:00
parent ae91e47a73
commit 753d8b020a
26 changed files with 1369 additions and 636 deletions

View File

@@ -0,0 +1,73 @@
/*
*
*/
package org.redkale.test.http;
import java.lang.reflect.Field;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.redkale.mq.HttpSimpleRequestCoder;
import org.redkale.net.client.ClientRequest;
import org.redkale.net.http.HttpSimpleRequest;
/**
*
* @author zhangjx
*/
public class RequestCoderTest {
private boolean main;
public static void main(String[] args) throws Throwable {
RequestCoderTest test = new RequestCoderTest();
test.main = true;
test.run1();
test.run2();
test.run3();
}
@Test
public void run1() throws Exception {
HttpSimpleRequest req1 = HttpSimpleRequest.create("/aaa");
System.out.println("simpleRequest1: " + req1);
byte[] bytes = HttpSimpleRequestCoder.getInstance().encode(req1);
HttpSimpleRequest req2 = HttpSimpleRequestCoder.getInstance().decode(bytes);
Field timeFiedl = ClientRequest.class.getDeclaredField("createTime");
timeFiedl.setAccessible(true);
timeFiedl.set(req2, req1.getCreateTime());
System.out.println("simpleRequest2: " + req2);
Assertions.assertEquals(req1.toString(), req2.toString());
}
@Test
public void run2() throws Exception {
HttpSimpleRequest req1 = HttpSimpleRequest.create("/aaa");
req1.addHeader("X-aaa", "aaa");
req1.param("bean", "{}");
System.out.println("simpleRequest1: " + req1);
byte[] bytes = HttpSimpleRequestCoder.getInstance().encode(req1);
HttpSimpleRequest req2 = HttpSimpleRequestCoder.getInstance().decode(bytes);
Field timeFiedl = ClientRequest.class.getDeclaredField("createTime");
timeFiedl.setAccessible(true);
timeFiedl.set(req2, req1.getCreateTime());
System.out.println("simpleRequest2: " + req2);
Assertions.assertEquals(req1.toString(), req2.toString());
}
@Test
public void run3() throws Exception {
HttpSimpleRequest req1 = HttpSimpleRequest.create("/aaa");
req1.addHeader("X-aaa", "aaa");
req1.addHeader("X-bbb", "bbb1");
req1.addHeader("X-bbb", "bbb2");
req1.param("bean", "{}");
System.out.println("simpleRequest1: " + req1);
byte[] bytes = HttpSimpleRequestCoder.getInstance().encode(req1);
HttpSimpleRequest req2 = HttpSimpleRequestCoder.getInstance().decode(bytes);
Field timeFiedl = ClientRequest.class.getDeclaredField("createTime");
timeFiedl.setAccessible(true);
timeFiedl.set(req2, req1.getCreateTime());
System.out.println("simpleRequest2: " + req2);
Assertions.assertEquals(req1.toString(), req2.toString());
}
}

View File

@@ -1,6 +1,7 @@
package org.redkale.test.rest;
import java.io.IOException;
import java.io.Serializable;
import java.util.*;
import org.redkale.annotation.Resource;
import org.redkale.net.http.*;
@@ -29,11 +30,11 @@ public class _DynHelloRestServlet1 extends SimpleRestServlet {
DefaultAnyValue conf = DefaultAnyValue.create("port", "" + port);
server.init(conf);
server.start();
Thread.sleep(100);
Utility.sleep(100);
HelloEntity entity = new HelloEntity();
entity.setHelloname("my name");
Map<String, String> headers = new HashMap<>();
Map<String, Serializable> headers = new HashMap<>();
headers.put("hello-res", "my res");
//headers.put(Rest.REST_HEADER_RESNAME, "my-res");
String url = "http://127.0.0.1:" + port + "/pipes/hello/update?entity={}&bean2={}";