Skip to content

Commit

Permalink
add it to httpContext
Browse files Browse the repository at this point in the history
  • Loading branch information
SentryMan committed Nov 7, 2024
1 parent d821f1e commit 1786945
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 25 deletions.
3 changes: 3 additions & 0 deletions avaje-sigma/src/main/java/io/avaje/sigma/HttpContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,9 @@ default String formParam(String key) {
/** Skip further request handling, */
void skipRemainingHandlers();

/** whether the the remaining handlers will be skipped */
boolean handlersSkipped();

/**
* Returns the value of the specified request header.
*
Expand Down
11 changes: 6 additions & 5 deletions avaje-sigma/src/main/java/io/avaje/sigma/core/SigmaContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import java.util.List;
import java.util.Map;

public final class SigmaContext implements HttpContext {
final class SigmaContext implements HttpContext {

public static final String CONTENT_TYPE = "Content-Type";

Expand Down Expand Up @@ -216,6 +216,11 @@ public void skipRemainingHandlers() {
this.skipRemaining = true;
}

@Override
public boolean handlersSkipped() {
return skipRemaining;
}

@Override
public HttpContext base64EncodedResult(String content) {
this.base64Encoded = true;
Expand All @@ -238,8 +243,4 @@ public AWSHttpResponse createResponse() {
return new AWSHttpResponse(
status, responseHeaders, multiValueResponseHeaders, body, base64Encoded);
}

public boolean handlersSkipped() {
return skipRemaining;
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package io.avaje.sigma.routes;

import io.avaje.sigma.Handler;
import io.avaje.sigma.HttpContext;
import io.avaje.sigma.Router;
import io.avaje.sigma.core.SigmaContext;

import java.util.Map;

/** Filter with special matchAll. */
Expand Down Expand Up @@ -32,8 +31,8 @@ public boolean matches(String requestUri) {
}

@Override
public void handle(SigmaContext ctx) throws Exception {
if (!ctx.handlersSkipped()) handler.handle(ctx);
public void handle(HttpContext ctx) throws Exception {
handler.handle(ctx);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package io.avaje.sigma.routes;

import io.avaje.sigma.Handler;
import io.avaje.sigma.core.SigmaContext;

import io.avaje.sigma.HttpContext;
import java.util.Map;

final class RouteEntry implements SpiRoutes.Entry {
Expand All @@ -21,8 +20,8 @@ public boolean matches(String requestUri) {
}

@Override
public void handle(SigmaContext ctx) throws Exception {
if (!ctx.handlersSkipped()) handler.handle(ctx);
public void handle(HttpContext ctx) throws Exception {
handler.handle(ctx);
}

@Override
Expand Down
10 changes: 4 additions & 6 deletions avaje-sigma/src/main/java/io/avaje/sigma/routes/Routes.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
import io.avaje.sigma.ExceptionHandler;
import io.avaje.sigma.HttpContext;
import io.avaje.sigma.Router;
import io.avaje.sigma.core.SigmaContext;

import java.util.EnumMap;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -44,18 +42,18 @@ public Entry match(Router.HttpMethod type, String pathInfo) {
}

@Override
public void before(String pathInfo, SigmaContext ctx) throws Exception {
public void before(String pathInfo, HttpContext ctx) throws Exception {
for (Entry beforeFilter : before) {
if (!ctx.handlersSkipped() && beforeFilter.matches(pathInfo)) {
if (beforeFilter.matches(pathInfo)) {
beforeFilter.handle(ctx);
}
}
}

@Override
public void after(String pathInfo, SigmaContext ctx) throws Exception {
public void after(String pathInfo, HttpContext ctx) throws Exception {
for (Entry afterFilter : after) {
if (!ctx.handlersSkipped() && afterFilter.matches(pathInfo)) {
if (afterFilter.matches(pathInfo)) {
afterFilter.handle(ctx);
}
}
Expand Down
10 changes: 4 additions & 6 deletions avaje-sigma/src/main/java/io/avaje/sigma/routes/SpiRoutes.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
package io.avaje.sigma.routes;

import java.util.Map;

import io.avaje.sigma.HttpContext;
import io.avaje.sigma.Router;
import io.avaje.sigma.core.SigmaContext;
import java.util.Map;

/** Route matching and filter handling. */
public sealed interface SpiRoutes permits Routes {
Expand All @@ -13,10 +11,10 @@ public sealed interface SpiRoutes permits Routes {
Entry match(Router.HttpMethod type, String pathInfo);

/** Execute all appropriate before filters for the given request URI. */
void before(String pathInfo, SigmaContext ctx) throws Exception;
void before(String pathInfo, HttpContext ctx) throws Exception;

/** Execute all appropriate after filters for the given request URI. */
void after(String pathInfo, SigmaContext ctx) throws Exception;
void after(String pathInfo, HttpContext ctx) throws Exception;

void handleException(HttpContext ctx, Exception e);

Expand All @@ -27,7 +25,7 @@ sealed interface Entry permits FilterEntry, RouteEntry {
boolean matches(String requestUri);

/** Handle the request. */
void handle(SigmaContext ctx) throws Exception;
void handle(HttpContext ctx) throws Exception;

/** Return the path parameter map given the uri. */
Map<String, String> pathParams(String uri);
Expand Down

0 comments on commit 1786945

Please sign in to comment.