Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
import java.util.List;

public interface Handler {
/**
* The default handler. It holds no state.
*/
Handler DEFAULT = new Handler() {};

default void log(LogLevel level, String message) throws WasmException {}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
public final class ProxyWasm implements Closeable {

private final ABI abi;
private final Handler pluginHandler;
private final WasiPreview1 wasi;

private final AtomicInteger nextContextID = new AtomicInteger(1);
Expand All @@ -33,6 +32,7 @@ public final class ProxyWasm implements Closeable {
private ProxyMap httpCallResponseHeaders;
private ProxyMap httpCallResponseTrailers;
private byte[] httpCallResponseBody;
private Handler pluginHandler;

private ProxyWasm(Builder other) throws StartException {
this.pluginHandler = Objects.requireNonNullElse(other.pluginHandler, new Handler() {});
Expand All @@ -52,6 +52,14 @@ private ProxyWasm(Builder other) throws StartException {
}
}

public Handler getPluginHandler() {
return pluginHandler;
}

public void setPluginHandler(Handler pluginHandler) {
this.pluginHandler = pluginHandler;
}

public void start() throws StartException {
if (pluginContext != null) {
return;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package io.roastedroot.proxywasm.plugin;

import io.roastedroot.proxywasm.ProxyMap;

public class HttpCallResponse {

public final int statusCode;
public final ProxyMap headers;
public final byte[] body;

public HttpCallResponse(int statusCode, ProxyMap headers, byte[] body) {
this.statusCode = statusCode;
this.headers = headers;
this.body = body;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package io.roastedroot.proxywasm.plugin;

public interface HttpCallResponseHandler {
void call(HttpCallResponse response);
}
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,11 @@ public SendResponse consumeSentHttpResponse() {
}

class HandlerImpl extends ChainedHandler {
private final Handler next = plugin.wasm.getPluginHandler();

@Override
protected Handler next() {
return plugin.handler;
return next;
}

public ProxyMap getHttpRequestHeaders() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package io.roastedroot.proxywasm.plugin;

import io.roastedroot.proxywasm.MetricType;

public class Metric {

final int id;
final MetricType type;
final String name;
long value;

public Metric(int id, MetricType type, String name) {
this.id = id;
this.type = type;
this.name = name;
}

public int id() {
return id;
}

public MetricType type() {
return type;
}

public String name() {
return name;
}

public long value() {
return value;
}
}
Loading