This commit is contained in:
Looly
2023-03-08 23:51:29 +08:00
parent e215f22292
commit 09b5cc671e
2 changed files with 27 additions and 278 deletions

View File

@@ -0,0 +1,27 @@
package cn.hutool.http.server;
import cn.hutool.core.lang.Console;
import cn.hutool.http.HttpUtil;
import cn.hutool.http.meta.Header;
public class RedirectServerTest {
public static void main(final String[] args) {
HttpUtil.createServer(8888).addAction("/redirect1", (request, response) -> {
response.addHeader(Header.LOCATION.getValue(),"http://localhost:8888/redirect2");
response.addHeader(Header.SET_COOKIE.getValue(),"redirect1=1; path=/; HttpOnly");
response.send(301);
}).addAction("/redirect2", (request, response) -> {
response.addHeader(Header.LOCATION.getValue(),"http://localhost:8888/redirect3");
response.addHeader(Header.SET_COOKIE.getValue(), "redirect2=2; path=/; HttpOnly");
response.send(301);
}).addAction("/redirect3", (request, response) -> {
response.addHeader(Header.LOCATION.getValue(),"http://localhost:8888/redirect4");
response.addHeader(Header.SET_COOKIE.getValue(),"redirect3=3; path=/; HttpOnly");
response.send(301);
}).addAction("/redirect4", (request, response) -> {
final String cookie = request.getHeader(Header.COOKIE);
Console.log(cookie);
response.sendOk();
}).start();
}
}