Skip to content

Commit

Permalink
v3.1.5 (#92)
Browse files Browse the repository at this point in the history
  • Loading branch information
scx567888 authored Oct 3, 2024
1 parent 7fbad36 commit c70502e
Show file tree
Hide file tree
Showing 45 changed files with 248 additions and 122 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

<artifactId>scx</artifactId>
<packaging>pom</packaging>
<version>3.1.4</version>
<version>3.1.5</version>

<name>SCX</name>
<url>https://github.com/scx567888/scx</url>
Expand Down
2 changes: 1 addition & 1 deletion scx-ansi/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>cool.scx</groupId>
<artifactId>scx</artifactId>
<version>3.1.4</version>
<version>3.1.5</version>
</parent>

<artifactId>scx-ansi</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion scx-common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>cool.scx</groupId>
<artifactId>scx</artifactId>
<version>3.1.4</version>
<version>3.1.5</version>
</parent>

<artifactId>scx-common</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion scx-config/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>cool.scx</groupId>
<artifactId>scx</artifactId>
<version>3.1.4</version>
<version>3.1.5</version>
</parent>

<artifactId>scx-config</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion scx-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>cool.scx</groupId>
<artifactId>scx</artifactId>
<version>3.1.4</version>
<version>3.1.5</version>
</parent>

<artifactId>scx-core</artifactId>
Expand Down
6 changes: 3 additions & 3 deletions scx-core/src/main/java/cool/scx/core/Scx.java
Original file line number Diff line number Diff line change
Expand Up @@ -173,11 +173,11 @@ private Scx run0() {
}
//6, 初始化服务器
var httpServerOptions = new ScxHttpServerOptions()
.setMaxPayloadSize(DEFAULT_BODY_LIMIT)
.setPort(this.scxOptions.port());
.maxPayloadSize(DEFAULT_BODY_LIMIT)
.port(this.scxOptions.port());
if (this.scxOptions.isHttpsEnabled()) {
var tls = getTls(this.scxOptions.sslPath(), this.scxOptions.sslPassword());
httpServerOptions.setTLS(tls);
httpServerOptions.tls(tls);
}
this.vertxHttpServer = new HelidonHttpServer(httpServerOptions);
this.vertxHttpServer.requestHandler(this.scxHttpRouter).webSocketHandler(this.webSocketRouter);
Expand Down
2 changes: 1 addition & 1 deletion scx-core/src/main/java/cool/scx/core/ScxVersion.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class ScxVersion {
/**
* SCX 版本号
*/
public static final String SCX_VERSION = "3.1.4";
public static final String SCX_VERSION = "3.1.5";

/**
* 在控制台上打印 banner
Expand Down
2 changes: 1 addition & 1 deletion scx-data-jdbc/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>cool.scx</groupId>
<artifactId>scx</artifactId>
<version>3.1.4</version>
<version>3.1.5</version>
</parent>

<artifactId>scx-data-jdbc</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion scx-data-mysql-x/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>cool.scx</groupId>
<artifactId>scx</artifactId>
<version>3.1.4</version>
<version>3.1.5</version>
</parent>

<artifactId>scx-data-mysql-x</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion scx-data/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>cool.scx</groupId>
<artifactId>scx</artifactId>
<version>3.1.4</version>
<version>3.1.5</version>
</parent>

<artifactId>scx-data</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion scx-ext/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>cool.scx</groupId>
<artifactId>scx</artifactId>
<version>3.1.4</version>
<version>3.1.5</version>
</parent>

<artifactId>scx-ext</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public static void startRedirect(int port) {
var newURI = "https" + oldURI.substring(4);
Redirection.ofTemporary(newURI).accept(c);
});
var httpServer = new HelidonHttpServer(new ScxHttpServerOptions().setPort(port));
var httpServer = new HelidonHttpServer(new ScxHttpServerOptions().port(port));
httpServer.requestHandler(router);

try {
Expand Down
2 changes: 1 addition & 1 deletion scx-ffm/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>cool.scx</groupId>
<artifactId>scx</artifactId>
<version>3.1.4</version>
<version>3.1.5</version>
</parent>

<artifactId>scx-ffm</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion scx-http-helidon/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>cool.scx</groupId>
<artifactId>scx</artifactId>
<version>3.1.4</version>
<version>3.1.5</version>
</parent>

<artifactId>scx-http-helidon</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,9 @@
import cool.scx.http.ScxHttpHeaders;
import cool.scx.http.ScxHttpHeadersWritable;
import cool.scx.http.uri.ScxURI;
import io.helidon.common.uri.UriEncoding;
import io.helidon.webclient.websocket.WsClient;
import io.helidon.websocket.WsSession;

import java.net.URI;
import java.util.function.Consumer;

/**
Expand Down Expand Up @@ -72,7 +70,7 @@ public void connect() {
}
}
var wsClient = wsClientBuilder.build();
wsClient.connect(URI.create(UriEncoding.encodeUri(uri.encode())), this);
wsClient.connect(uri.toURI(), this);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@

import cool.scx.http.ScxHttpHeaders;
import cool.scx.http.ScxHttpHeadersWritable;
import cool.scx.http.uri.ScxURI;
import cool.scx.http.uri.ScxURIWritable;
import cool.scx.reflect.ReflectFactory;
import io.helidon.http.Header;
import io.helidon.http.Headers;
import io.helidon.http.HttpPrologue;
import io.helidon.http.PathMatchers;
import io.helidon.webserver.websocket.WsRoute;
import io.helidon.webserver.websocket.WsRouting;
Expand Down Expand Up @@ -43,4 +46,14 @@ public static ScxHttpHeadersWritable convertHeaders(Headers o) {
return h;
}

public static ScxURIWritable createScxURI(HttpPrologue p) {
var path = p.uriPath().path();
var query = p.query().value();
var fragment = p.fragment().hasValue() ? p.fragment().value() : null;
return ScxURI.of()
.path(path)
.query(query)
.fragment(fragment);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import cool.scx.http.ScxClientWebSocketBuilder;
import cool.scx.http.ScxHttpClient;
import cool.scx.http.ScxHttpClientOptions;
import io.helidon.webclient.api.Proxy;
import io.helidon.webclient.api.WebClient;

/**
Expand All @@ -11,9 +12,20 @@
public class HelidonHttpClient implements ScxHttpClient {

private final WebClient webClient;
private final ScxHttpClientOptions options;

public HelidonHttpClient(ScxHttpClientOptions options) {
this.webClient = WebClient.builder().build();
this.options = options;
var builder = WebClient.builder();
if (options.proxy() != null) {
var p = options.proxy();
var proxy = Proxy.builder().host(p.host()).port(p.port()).username(p.username());
if (p.password() != null) {
proxy.password(p.password());
}
builder.proxy(proxy.build());
}
this.webClient = builder.build();
}

public HelidonHttpClient() {
Expand All @@ -22,12 +34,16 @@ public HelidonHttpClient() {

@Override
public HelidonHttpClientRequest request() {
return new HelidonHttpClientRequest(webClient);
return new HelidonHttpClientRequest(this.webClient, this);
}

@Override
public ScxClientWebSocketBuilder webSocket() {
return new HelidonClientWebSocket();
}

public ScxHttpClientOptions options() {
return options;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,25 @@
public class HelidonHttpClientRequest extends ScxHttpClientRequestBase {

private final WebClient webClient;
private final HelidonHttpClient client;

public HelidonHttpClientRequest(WebClient webClient) {
public HelidonHttpClientRequest(WebClient webClient, HelidonHttpClient client) {
this.webClient = webClient;
this.method = HttpMethod.GET;
this.client = client;
}

@Override
public HelidonHttpClientResponse send(MediaWriter writer) {
var r = webClient.method(Method.create(method.value()));
//这里已经转换为 URL 编码了 无需再转换一遍
r.uri(uri.encode());
r.uri(uri.toURI());
writer.beforeWrite(headers, ScxHttpHeaders.of());
for (var h : headers) {
r.header(HeaderNames.create(h.getKey().value()), h.getValue());
}
var httpClientResponse = r.outputStream(writer::write);
return new HelidonHttpClientResponse(httpClientResponse);
return new HelidonHttpClientResponse(httpClientResponse, this.client);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ public class HelidonHttpClientResponse implements ScxHttpClientResponse {
private final ScxHttpHeaders headers;
private final ScxHttpBody body;

public HelidonHttpClientResponse(HttpClientResponse response) {
public HelidonHttpClientResponse(HttpClientResponse response, HelidonHttpClient client) {
this.response = response;
this.status = HttpStatusCode.of(response.status().code());
this.headers = convertHeaders(response.headers());
this.body = new ScxHttpBodyImpl(response.entity().inputStream(), this.headers);
this.body = new ScxHttpBodyImpl(response.entity().inputStream(), this.headers, client.options().bodyBufferSize());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public HelidonHttpRouting(HelidonHttpServer server) {
@Override
public void route(ConnectionContext ctx, RoutingRequest request, RoutingResponse response) {
if (server.requestHandler != null) {
server.requestHandler.accept(new HelidonHttpServerRequest(ctx, request, response));
server.requestHandler.accept(new HelidonHttpServerRequest(ctx, request, response, server));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,22 @@
public class HelidonHttpServer implements ScxHttpServer {

private final WebServer webServer;
private final ScxHttpServerOptions options;
Consumer<ScxHttpServerRequest> requestHandler;
Consumer<ScxServerWebSocket> webSocketHandler;
Consumer<Throwable> errorHandler;

public HelidonHttpServer(ScxHttpServerOptions options) {
this.options = options;
var httpRouting = new HelidonHttpRouting(this);
var webSocketRouting = createHelidonWebSocketRouting(this);
var builder = WebServer.builder()
.addRouting(httpRouting)
.addRouting(webSocketRouting)
.maxPayloadSize(options.getMaxPayloadSize())
.port(options.getPort());
if (options.getTLS() != null) {
builder.tls((Tls) options.getTLS());
.maxPayloadSize(options.maxPayloadSize())
.port(options.port());
if (options.tls() != null) {
builder.tls((Tls) options.tls());
}
this.webServer = builder.build();
this.requestHandler = null;
Expand Down Expand Up @@ -71,4 +73,8 @@ public int port() {
return this.webServer.port();
}

public ScxHttpServerOptions options() {
return options;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import io.helidon.webserver.http.RoutingResponse;

import static cool.scx.http.helidon.HelidonHelper.convertHeaders;
import static cool.scx.http.helidon.HelidonHelper.createScxURI;

/**
* HelidonHttpServerRequest
Expand All @@ -21,15 +22,16 @@ class HelidonHttpServerRequest implements ScxHttpServerRequest {
private final ScxHttpServerResponse response;
private final HelidonPeerInfo remotePeer;
private final HelidonPeerInfo localPeer;
private final HelidonHttpServer server;

public HelidonHttpServerRequest(ConnectionContext ctx, RoutingRequest request, RoutingResponse response) {
public HelidonHttpServerRequest(ConnectionContext ctx, RoutingRequest request, RoutingResponse response, HelidonHttpServer server) {
this.server = server;
var p = request.prologue();
request.path(new HelidonRoutePath(p));
this.method = ScxHttpMethod.of(p.method().text());
this.uri = ScxURI.of(request.requestedUri().toUri());
this.uri = createScxURI(p);
this.version = HttpVersion.of(p.rawProtocol());
this.headers = convertHeaders(request.headers());
this.body = new ScxHttpBodyImpl(request.content().inputStream(), this.headers);
this.body = new ScxHttpBodyImpl(request.content().inputStream(), this.headers, server.options().bodyBufferSize());
this.response = new HelidonHttpServerResponse(this, response);
this.remotePeer = new HelidonPeerInfo(request.remotePeer());
this.localPeer = new HelidonPeerInfo(request.localPeer());
Expand Down

This file was deleted.

Loading

0 comments on commit c70502e

Please sign in to comment.