Skip to content

Commit

Permalink
Merge pull request #544 from SDCISA-13736-ApplyFindings-20240105-1340
Browse files Browse the repository at this point in the history
  • Loading branch information
hiddenalpha authored Jan 9, 2024
2 parents b72ba30 + cfa2ffb commit 51b5486
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public BufferBridge(Vertx vertx) {
}

protected void pump() {
vertx.runOnContext(event -> {
vertx.runOnContext(nothing -> {
try {
if (!queue.isEmpty()) {
log.trace("Pumping from queue");
Expand Down Expand Up @@ -60,6 +60,8 @@ protected void doWrite(Buffer chunk) {
} catch (Exception e) {
if (exceptionHandler != null) {
exceptionHandler.handle(e);
}else{
log.warn("TODO error handling", e);
}
}
} else {
Expand All @@ -80,6 +82,8 @@ protected Future<Void> doEnd() {
} catch (Exception e) {
if (exceptionHandler != null) {
exceptionHandler.handle(e);
}else{
log.warn("TODO error handling", e);
}
}
endHandler = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,35 @@

import io.netty.handler.codec.http.QueryStringDecoder;
import io.vertx.codegen.annotations.Nullable;
import io.vertx.core.*;
import io.vertx.core.AsyncResult;
import io.vertx.core.Future;
import io.vertx.core.Handler;
import io.vertx.core.MultiMap;
import io.vertx.core.Promise;
import io.vertx.core.Vertx;
import io.vertx.core.buffer.Buffer;
import io.vertx.core.http.*;
import io.vertx.core.http.Cookie;
import io.vertx.core.http.HttpClientRequest;
import io.vertx.core.http.HttpClientResponse;
import io.vertx.core.http.HttpConnection;
import io.vertx.core.http.HttpMethod;
import io.vertx.core.http.HttpServerRequest;
import io.vertx.core.http.HttpServerResponse;
import io.vertx.core.http.HttpVersion;
import io.vertx.core.http.impl.headers.HeadersMultiMap;
import io.vertx.core.json.JsonArray;
import io.vertx.core.json.JsonObject;
import io.vertx.core.net.NetSocket;
import io.vertx.core.net.SocketAddress;
import io.vertx.core.net.impl.SocketAddressImpl;
import io.vertx.ext.auth.User;
import io.vertx.ext.web.*;
import io.vertx.ext.web.FileUpload;
import io.vertx.ext.web.LanguageHeader;
import io.vertx.ext.web.ParsedHeaderValues;
import io.vertx.ext.web.Route;
import io.vertx.ext.web.RoutingContext;
import io.vertx.ext.web.Session;
import org.slf4j.Logger;

import javax.net.ssl.SSLSession;
import javax.security.cert.X509Certificate;
Expand All @@ -21,12 +39,15 @@
import java.util.Map;
import java.util.Set;

import static org.slf4j.LoggerFactory.getLogger;

/**
* Bridges a HttpClientRequest to a HttpServerRequest sent to a request handler.
*
* @author https://github.com/lbovet [Laurent Bovet]
*/
public class LocalHttpClientRequest extends BufferBridge implements FastFailHttpClientRequest {
private static final Logger log = getLogger(LocalHttpClientRequest.class);
private MultiMap headers = new HeadersMultiMap();
private MultiMap params;
private HttpMethod method;
Expand Down Expand Up @@ -776,6 +797,8 @@ public boolean writeQueueFull() {

@Override
public HttpClientRequest drainHandler(Handler<Void> handler) {
log.warn("Happy debugging, as this impl will just ignore your drainHandler anyway",
new Exception("may this stacktrace lead you where this problem comes from"));
return this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,25 @@
import io.vertx.core.http.Http2Settings;
import io.vertx.core.http.HttpConnection;
import io.vertx.core.net.SocketAddress;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.net.ssl.SSLPeerUnverifiedException;
import javax.net.ssl.SSLSession;
import javax.security.cert.X509Certificate;
import java.security.cert.Certificate;
import java.util.List;

import static org.slf4j.LoggerFactory.getLogger;

/**
* this is a mock-connection object which silently ignores (nearly) HTTP/1.1 relevant method calls and never throws exceptions
* we need this to be able to set appropriate exception- and close-handlers in e.g. Gateleen's Forwarder (gateleen-routing)
*/
public class LocalHttpConnection implements HttpConnection {

private static final Logger log = getLogger(LocalHttpConnection.class);

@Override
public HttpConnection goAway(long errorCode, int lastStreamId, Buffer debugData) {
throw new UnsupportedOperationException("LocalConnection don't support this");
Expand Down Expand Up @@ -48,6 +55,8 @@ public Future<Void> shutdown(long timeoutMs) {

@Override
public HttpConnection closeHandler(Handler<Void> handler) {
log.warn("Happy debugging, as this impl is going to ignore your closeHandler anyway",
new Exception("may this stacktrace help you"));
return this;
}

Expand Down Expand Up @@ -99,6 +108,8 @@ public HttpConnection pingHandler(@Nullable Handler<Buffer> handler) {

@Override
public HttpConnection exceptionHandler(Handler<Throwable> handler) {
log.warn("Happy debugging, as this impl just ignores your exceptionHandler anyway",
new Exception("stacktrace"));
return this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public static void logRequest(EventBus eventBus, final HttpServerRequest request

public static void logRequest(EventBus eventBus, final HttpServerRequest request, final int status, Buffer data, final MultiMap responseHeaders) {
Logger log = RequestLoggerFactory.getLogger(RequestLogger.class, request);
log.info("Notify logging to eventually log the payload and headers of request to uri " + request.uri());
log.info("Notify logging to eventually log the payload and headers of request to uri {}", request.uri());
JsonObject logEntry = new JsonObject();
logEntry.put(REQUEST_URI, request.uri());
logEntry.put(REQUEST_METHOD, request.method().name());
Expand All @@ -52,9 +52,9 @@ public static void logRequest(EventBus eventBus, final HttpServerRequest request

eventBus.request(Address.requestLoggingConsumerAddress(), logEntry, (Handler<AsyncResult<Message<JsonObject>>>) reply -> {
if (reply.failed()) {
log.warn("Failed to log the payload and headers. Cause: " + reply.cause().getMessage());
log.warn("Failed to log the payload and headers. Cause: {}", reply.cause().getMessage());
} else if (ERROR.equals(reply.result().body().getString("status"))) {
log.warn("Failed to log the payload and headers. Cause: " + reply.result().body().getString("message"));
log.warn("Failed to log the payload and headers. Cause: {}", reply.result().body().getString("message"));
}
});
}
Expand Down

0 comments on commit 51b5486

Please sign in to comment.