Skip to content

Commit b871ac4

Browse files
authored
chore: tweak the output of get scheme (support HTTP1.1) (#76)
1 parent 32ecdfe commit b871ac4

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed

src/http/ngx_http_wasm_api.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -946,8 +946,13 @@ ngx_http_wasm_req_get_header(ngx_http_request_t *r, char *key, int32_t key_size
946946
break;
947947

948948
case PROXY_WASM_HEADER_SCHEME:
949-
val = r->schema.data;
950-
val_len = r->schema.len;
949+
if (r->connection->ssl) {
950+
val = scheme_https.data;
951+
val_len = scheme_https.len;
952+
} else {
953+
val = scheme_http.data;
954+
val_len = scheme_http.len;
955+
}
951956
break;
952957

953958
default:

t/http_req_header.t

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,7 @@ get request method: DELETE,
374374

375375

376376

377-
=== TEST 20: get schema
377+
=== TEST 20: get schema(http2)
378378
--- http2
379379
--- config
380380
location /t {
@@ -434,3 +434,20 @@ location /t {
434434
end
435435
}
436436
}
437+
438+
439+
440+
=== TEST 23: get schema(http)
441+
--- config
442+
location /t {
443+
content_by_lua_block {
444+
local wasm = require("resty.proxy-wasm")
445+
local plugin = assert(wasm.load("plugin", "t/testdata/http_header/main.go.wasm"))
446+
local ctx = assert(wasm.on_configure(plugin, 'req_scheme_get'))
447+
assert(wasm.on_http_request_headers(ctx))
448+
}
449+
}
450+
--- grep_error_log eval
451+
qr/get request scheme: \S+/
452+
--- grep_error_log_out
453+
get request scheme: http,

0 commit comments

Comments
 (0)