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
8 changes: 8 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

<modules>
<module>proxy-wasm-java-host</module>
<module>proxy-wasm-jaxrs</module>
</modules>

<properties>
Expand All @@ -32,18 +33,24 @@
<maven.compiler.failOnWarning>true</maven.compiler.failOnWarning>
<maven.dependency.failOnWarning>true</maven.dependency.failOnWarning>
<project.build.outputTimestamp>2023-01-01T00:00:00Z</project.build.outputTimestamp>
<skipITs>true</skipITs>

<!-- build tool versions -->
<checkstyle.version>10.21.4</checkstyle.version>
<maven-checkstyle-plugin.version>3.6.0</maven-checkstyle-plugin.version>
<spotless-maven-plugin.version>2.44.3</spotless-maven-plugin.version>
<maven.compiler.version>3.14.0</maven.compiler.version>
<surefire-plugin.version>3.5.2</surefire-plugin.version>

<!-- test time versions -->
<junit.version>5.12.0</junit.version>

<!-- runtime versions -->
<chicory.version>1.1.0</chicory.version>
<quarkus.platform.artifact-id>quarkus-bom</quarkus.platform.artifact-id>
<quarkus.platform.group-id>io.quarkus.platform</quarkus.platform.group-id>
<quarkus.platform.version>3.19.3</quarkus.platform.version>

</properties>

<build>
Expand Down Expand Up @@ -188,6 +195,7 @@
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven.compiler.version}</version>
<configuration>
<parameters>true</parameters>
<source>11</source>
<target>11</target>
<annotationProcessorPathsUseDepMgmt>true</annotationProcessorPathsUseDepMgmt>
Expand Down
1 change: 0 additions & 1 deletion proxy-wasm-java-host/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
<version>1.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

<artifactId>proxy-wasm-java-host</artifactId>
<packaging>jar</packaging>

Expand Down
124 changes: 54 additions & 70 deletions proxy-wasm-java-host/src/main/java/io/roastedroot/proxywasm/ABI.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,35 +21,35 @@ class ABI {

private Handler handler;
private Memory memory;
private ExportFunction initializeFn;
private ExportFunction mainFn;
private ExportFunction startFn;
private ExportFunction proxyOnContextCreateFn;
private ExportFunction proxyOnDoneFn;
private ExportFunction mallocFn;
private ExportFunction proxyOnLogFn;
private ExportFunction proxyOnDeleteFn;
private ExportFunction proxyOnVmStartFn;
private ExportFunction proxyOnConfigureFn;
private ExportFunction proxyOnTickFn;
private ExportFunction proxyOnNewConnectionFn;
private ExportFunction proxyOnDownstreamDataFn;
private ExportFunction proxyOnDownstreamConnectionCloseFn;
private ExportFunction proxyOnUpstreamDataFn;
private ExportFunction proxyOnUpstreamConnectionCloseFn;
private ExportFunction proxyOnRequestHeadersFn;
private ExportFunction proxyOnRequestBodyFn;
private ExportFunction proxyOnRequestTrailersFn;
private ExportFunction proxyOnResponseHeadersFn;
private ExportFunction proxyOnResponseBodyFn;
private ExportFunction proxyOnResponseTrailersFn;
private ExportFunction proxyOnHttpCallResponseFn;
private ExportFunction proxyOnGrpcReceiveInitialMetadataFn;
private ExportFunction proxyOnGrpcReceiveFn;
private ExportFunction proxyOnGrpcReceiveTrailingMetadataFn;
private ExportFunction proxyOnGrpcCloseFn;
private ExportFunction proxyOnQueueReadyFn;
private ExportFunction proxyOnForeignFunctionFn;
ExportFunction initializeFn;
ExportFunction mainFn;
ExportFunction startFn;
ExportFunction proxyOnContextCreateFn;
ExportFunction proxyOnDoneFn;
ExportFunction mallocFn;
ExportFunction proxyOnLogFn;
ExportFunction proxyOnDeleteFn;
ExportFunction proxyOnVmStartFn;
ExportFunction proxyOnConfigureFn;
ExportFunction proxyOnTickFn;
ExportFunction proxyOnNewConnectionFn;
ExportFunction proxyOnDownstreamDataFn;
ExportFunction proxyOnDownstreamConnectionCloseFn;
ExportFunction proxyOnUpstreamDataFn;
ExportFunction proxyOnUpstreamConnectionCloseFn;
ExportFunction proxyOnRequestHeadersFn;
ExportFunction proxyOnRequestBodyFn;
ExportFunction proxyOnRequestTrailersFn;
ExportFunction proxyOnResponseHeadersFn;
ExportFunction proxyOnResponseBodyFn;
ExportFunction proxyOnResponseTrailersFn;
ExportFunction proxyOnHttpCallResponseFn;
ExportFunction proxyOnGrpcReceiveInitialMetadataFn;
ExportFunction proxyOnGrpcReceiveFn;
ExportFunction proxyOnGrpcReceiveTrailingMetadataFn;
ExportFunction proxyOnGrpcCloseFn;
ExportFunction proxyOnQueueReadyFn;
ExportFunction proxyOnForeignFunctionFn;

Handler getHandler() {
return handler;
Expand Down Expand Up @@ -866,7 +866,29 @@ int proxyGetHeaderMapValue(
@WasmExport
int proxyAddHeaderMapValue(
int mapType, int keyDataPtr, int keySize, int valueDataPtr, int valueSize) {
return proxyReplaceHeaderMapValue(mapType, keyDataPtr, keySize, valueDataPtr, valueSize);
try {
// Get the header map based on the map type
ProxyMap headerMap = getMap(mapType);
if (headerMap == null) {
return WasmResult.BAD_ARGUMENT.getValue();
}

// Get key from memory
String key = string(readMemory(keyDataPtr, keySize));

// Get value from memory
String value = string(readMemory(valueDataPtr, valueSize));

// Add value in map
headerMap.add(key, value);

return WasmResult.OK.getValue();

} catch (WasmRuntimeException e) {
return WasmResult.INVALID_MEMORY_ACCESS.getValue();
} catch (WasmException e) {
return e.result().getValue();
}
}

/**
Expand Down Expand Up @@ -897,9 +919,7 @@ int proxyReplaceHeaderMapValue(
String value = string(readMemory(valueDataPtr, valueSize));

// Replace value in map
var copy = new ArrayProxyMap(headerMap);
copy.put(key, value);
setMap(mapType, copy);
headerMap.put(key, value);

return WasmResult.OK.getValue();

Expand Down Expand Up @@ -935,9 +955,7 @@ int proxyRemoveHeaderMapValue(int mapType, int keyDataPtr, int keySize) {
}

// Remove key from map
var copy = new ArrayProxyMap(headerMap);
copy.remove(key);
setMap(mapType, copy);
headerMap.remove(key);

return WasmResult.OK.getValue();

Expand Down Expand Up @@ -982,40 +1000,6 @@ private ProxyMap getMap(int mapType) {
return null;
}

/**
* Set a header map based on the map type.
*
* @param mapType The type of map to set
* @param map The header map to set
* @return WasmResult indicating success or failure
*/
private WasmResult setMap(int mapType, ProxyMap map) {
var knownType = MapType.fromInt(mapType);
if (knownType == null) {
return handler.setCustomHeaders(mapType, map);
}

switch (knownType) {
case HTTP_REQUEST_HEADERS:
return handler.setHttpRequestHeaders(map);
case HTTP_REQUEST_TRAILERS:
return handler.setHttpRequestTrailers(map);
case HTTP_RESPONSE_HEADERS:
return handler.setHttpResponseHeaders(map);
case HTTP_RESPONSE_TRAILERS:
return handler.setHttpResponseTrailers(map);
case HTTP_CALL_RESPONSE_HEADERS:
return handler.setHttpCallResponseHeaders(map);
case HTTP_CALL_RESPONSE_TRAILERS:
return handler.setHttpCallResponseTrailers(map);
case GRPC_RECEIVE_INITIAL_METADATA:
return handler.setGrpcReceiveInitialMetaData(map);
case GRPC_RECEIVE_TRAILING_METADATA:
return handler.setGrpcReceiveTrailerMetaData(map);
}
return WasmResult.NOT_FOUND;
}

/**
* Decodes a byte array containing map data into a Map of String key-value pairs.
* <p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,46 +64,6 @@ public WasmResult setCustomHeaders(int mapType, ProxyMap map) {
return next().setCustomHeaders(mapType, map);
}

@Override
public WasmResult setHttpRequestHeaders(ProxyMap headers) {
return next().setHttpRequestHeaders(headers);
}

@Override
public WasmResult setHttpRequestTrailers(ProxyMap trailers) {
return next().setHttpRequestTrailers(trailers);
}

@Override
public WasmResult setHttpResponseHeaders(ProxyMap headers) {
return next().setHttpResponseHeaders(headers);
}

@Override
public WasmResult setHttpResponseTrailers(ProxyMap trailers) {
return next().setHttpResponseTrailers(trailers);
}

@Override
public WasmResult setHttpCallResponseHeaders(ProxyMap headers) {
return next().setHttpCallResponseHeaders(headers);
}

@Override
public WasmResult setHttpCallResponseTrailers(ProxyMap trailers) {
return next().setHttpCallResponseTrailers(trailers);
}

@Override
public WasmResult setGrpcReceiveInitialMetaData(ProxyMap metadata) {
return next().setGrpcReceiveInitialMetaData(metadata);
}

@Override
public WasmResult setGrpcReceiveTrailerMetaData(ProxyMap metadata) {
return next().setGrpcReceiveTrailerMetaData(metadata);
}

@Override
public byte[] getProperty(List<String> key) throws WasmException {
return next().getProperty(key);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@ public int id() {
return id;
}

public ProxyWasm getProxyWasm() {
return proxyWasm;
}

ProxyWasm proxyWasm() {
return proxyWasm;
}

public void close() {
if (closeStarted) {
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -298,86 +298,6 @@ default WasmResult setCustomHeaders(int mapType, ProxyMap map) {
return WasmResult.UNIMPLEMENTED;
}

/**
* Set the HTTP request headers.
*
* @param headers The headers to set
* @return WasmResult indicating success or failure
*/
default WasmResult setHttpRequestHeaders(ProxyMap headers) {
return WasmResult.UNIMPLEMENTED;
}

/**
* Set the HTTP request trailers.
*
* @param trailers The trailers to set
* @return WasmResult indicating success or failure
*/
default WasmResult setHttpRequestTrailers(ProxyMap trailers) {
return WasmResult.UNIMPLEMENTED;
}

/**
* Set the HTTP response headers.
*
* @param headers The headers to set
* @return WasmResult indicating success or failure
*/
default WasmResult setHttpResponseHeaders(ProxyMap headers) {
return WasmResult.UNIMPLEMENTED;
}

/**
* Set the HTTP response trailers.
*
* @param trailers The trailers to set
* @return WasmResult indicating success or failure
*/
default WasmResult setHttpResponseTrailers(ProxyMap trailers) {
return WasmResult.UNIMPLEMENTED;
}

/**
* Set the HTTP call response headers.
*
* @param headers The headers to set
* @return WasmResult indicating success or failure
*/
default WasmResult setHttpCallResponseHeaders(ProxyMap headers) {
return WasmResult.UNIMPLEMENTED;
}

/**
* Set the HTTP call response trailers.
*
* @param trailers The trailers to set
* @return WasmResult indicating success or failure
*/
default WasmResult setHttpCallResponseTrailers(ProxyMap trailers) {
return WasmResult.UNIMPLEMENTED;
}

/**
* Set the gRPC receive initial metadata.
*
* @param metadata The metadata to set
* @return WasmResult indicating success or failure
*/
default WasmResult setGrpcReceiveInitialMetaData(ProxyMap metadata) {
return WasmResult.UNIMPLEMENTED;
}

/**
* Set the gRPC receive trailer metadata.
*
* @param metadata The metadata to set
* @return WasmResult indicating success or failure
*/
default WasmResult setGrpcReceiveTrailerMetaData(ProxyMap metadata) {
return WasmResult.UNIMPLEMENTED;
}

default WasmResult setAction(StreamType streamType, Action action) {
return WasmResult.UNIMPLEMENTED;
}
Expand Down
Loading
Loading