Skip to content

Commit bdf1593

Browse files
authored
feat: support get scheme for h2 request header (#59)
1 parent b3883b3 commit bdf1593

File tree

3 files changed

+33
-1
lines changed

3 files changed

+33
-1
lines changed

src/http/ngx_http_wasm_api.c

+7-1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ typedef struct {
2121
enum {
2222
WASM_H2_HEADER_PATH = 1,
2323
WASM_H2_HEADER_METHOD,
24+
WASM_H2_HEADER_SCHEME,
2425
};
2526

2627
#define STR_BUF_SIZE 4096
@@ -77,6 +78,7 @@ static char *str_buf[STR_BUF_SIZE] = {0};
7778
static ngx_http_wasm_h2_header_t wasm_h2_header_static_table[] = {
7879
{ngx_string(":path"), WASM_H2_HEADER_PATH},
7980
{ngx_string(":method"), WASM_H2_HEADER_METHOD},
81+
{ngx_string(":scheme"), WASM_H2_HEADER_SCHEME},
8082
};
8183

8284

@@ -803,7 +805,11 @@ ngx_http_wasm_req_get_header(ngx_http_request_t *r, char *key, int32_t key_size
803805
val_len = r->method_name.len;
804806
break;
805807

806-
/* todo: scheme https://github.com/api7/wasm-nginx-module/issues/47 */
808+
case WASM_H2_HEADER_SCHEME:
809+
val = r->schema.data;
810+
val_len = r->schema.len;
811+
break;
812+
807813
default:
808814
break;
809815
}

t/http_req_header.t

+18
Original file line numberDiff line numberDiff line change
@@ -367,3 +367,21 @@ DELETE /t
367367
qr/get request method: \S+/
368368
--- grep_error_log_out
369369
get request method: DELETE,
370+
371+
372+
373+
=== TEST 20: get schema
374+
--- http2
375+
--- config
376+
location /t {
377+
content_by_lua_block {
378+
local wasm = require("resty.proxy-wasm")
379+
local plugin = assert(wasm.load("plugin", "t/testdata/http_header/main.go.wasm"))
380+
local ctx = assert(wasm.on_configure(plugin, 'req_scheme_get'))
381+
assert(wasm.on_http_request_headers(ctx))
382+
}
383+
}
384+
--- grep_error_log eval
385+
qr/get request scheme: \S+/
386+
--- grep_error_log_out
387+
get request scheme: http,

t/testdata/http_header/main.go

+8
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,14 @@ func (ctx *httpContext) OnHttpRequestHeaders(numHeaders int, endOfStream bool) t
9090
return types.ActionContinue
9191
}
9292
proxywasm.LogWarnf("get request method: %v", res)
93+
94+
case "req_scheme_get":
95+
res, err := proxywasm.GetHttpRequestHeader(":scheme")
96+
if err != nil {
97+
proxywasm.LogErrorf("error get request scheme: %v", err)
98+
return types.ActionContinue
99+
}
100+
proxywasm.LogWarnf("get request scheme: %v", res)
93101
}
94102

95103
return types.ActionContinue

0 commit comments

Comments
 (0)