Skip to content

Commit

Permalink
Added Response#noLog()
Browse files Browse the repository at this point in the history
  • Loading branch information
LatvianModder committed Oct 17, 2023
1 parent 6eb9214 commit 66081e1
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
24 changes: 24 additions & 0 deletions src/main/java/dev/latvian/apps/webutils/net/NoLogResponse.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package dev.latvian.apps.webutils.net;

import io.javalin.http.Context;
import io.javalin.http.HttpStatus;

import java.net.http.HttpRequest;

record NoLogResponse(Response original) implements Response {
@Override
public HttpStatus getStatus() {
return original.getStatus();
}

@Override
public void result(Context ctx) {
original.result(ctx);
ctx.attribute("nolog", true);
}

@Override
public HttpRequest.BodyPublisher bodyPublisher() {
return original.bodyPublisher();
}
}
8 changes: 6 additions & 2 deletions src/main/java/dev/latvian/apps/webutils/net/Response.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ static Response permanentRedirect(String path) {

void result(Context ctx);

default HttpRequest.BodyPublisher bodyPublisher() {
throw new IllegalStateException("Body publisher not supported");
}

default Response withCookie(Cookie cookie) {
return new ResponseWithCookie(this, cookie);
}
Expand All @@ -56,7 +60,7 @@ default Response privateCache(Duration duration) {
return cache(duration, true);
}

default HttpRequest.BodyPublisher bodyPublisher() {
throw new IllegalStateException("Body publisher not supported");
default Response noLog() {
return new NoLogResponse(this);
}
}

0 comments on commit 66081e1

Please sign in to comment.