forked from roastedroot/proxy-wasm-java-host
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHttpContext.java
More file actions
55 lines (46 loc) · 1.85 KB
/
HttpContext.java
File metadata and controls
55 lines (46 loc) · 1.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package io.roastedroot.proxywasm;
import static io.roastedroot.proxywasm.Helpers.len;
public class HttpContext extends Context {
private final Handler handler;
HttpContext(ProxyWasm proxyWasm, Handler handler) {
super(proxyWasm);
this.handler = handler;
}
Handler handler() {
return handler;
}
public Action callOnRequestHeaders(boolean endOfStream) {
var headers = handler.getHttpRequestHeaders();
int result = proxyWasm.abi().proxyOnRequestHeaders(id, len(headers), endOfStream ? 1 : 0);
Action action = Action.fromInt(result);
handler.setAction(StreamType.REQUEST, action);
return action;
}
public Action callOnResponseHeaders(boolean endOfStream) {
var headers = handler.getHttpResponseHeaders();
int result = proxyWasm.abi().proxyOnResponseHeaders(id, len(headers), endOfStream ? 1 : 0);
Action action = Action.fromInt(result);
handler.setAction(StreamType.RESPONSE, action);
return action;
}
public Action callOnRequestBody(boolean endOfStream) {
var requestBody = handler.getHttpRequestBody();
int result =
proxyWasm
.abi()
.proxyOnRequestBody(id, Helpers.len(requestBody), endOfStream ? 1 : 0);
Action action = Action.fromInt(result);
handler.setAction(StreamType.REQUEST, action);
return action;
}
public Action callOnResponseBody(boolean endOfStream) {
var responseBody = handler.getHttpResponseBody();
int result =
proxyWasm
.abi()
.proxyOnResponseBody(id, Helpers.len(responseBody), endOfStream ? 1 : 0);
Action action = Action.fromInt(result);
handler.setAction(StreamType.RESPONSE, action);
return action;
}
}