This commit is contained in:
Looly
2022-02-10 00:17:25 +08:00
parent 9b01a23a60
commit 7116177225
3 changed files with 13 additions and 2 deletions

View File

@@ -4,6 +4,7 @@ import cn.hutool.core.util.CharsetUtil;
import com.sun.net.httpserver.HttpContext;
import com.sun.net.httpserver.HttpExchange;
import java.io.Closeable;
import java.nio.charset.Charset;
/**
@@ -12,7 +13,7 @@ import java.nio.charset.Charset;
* @author looly
* @since 5.2.6
*/
public class HttpServerBase {
public class HttpServerBase implements Closeable {
final static Charset DEFAULT_CHARSET = CharsetUtil.CHARSET_UTF_8;
@@ -45,4 +46,12 @@ public class HttpServerBase {
public HttpContext getHttpContext() {
return getHttpExchange().getHttpContext();
}
/**
* 调用{@link HttpExchange#close()},关闭请求流和响应流
*/
@Override
public void close() {
this.httpExchange.close();
}
}

View File

@@ -33,5 +33,6 @@ public class ActionHandler implements HttpHandler {
new HttpServerRequest(httpExchange),
new HttpServerResponse(httpExchange)
);
httpExchange.close();
}
}