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
2 changes: 1 addition & 1 deletion config
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ ngx_module_srcs=" \
$ngx_addon_dir/src/http/ngx_http_wasm_api.c \
$ngx_addon_dir/src/http/ngx_http_wasm_call.c \
$ngx_addon_dir/src/http/ngx_http_wasm_state.c \
$ngx_addon_dir/src/http/ngx_http_wasm_map.c \
$ngx_addon_dir/src/proxy_wasm/proxy_wasm_map.c \
$ngx_addon_dir/src/vm/wasmtime.c \
$ngx_addon_dir/src/vm/vm.c \
"
Expand Down
48 changes: 24 additions & 24 deletions src/http/ngx_http_wasm_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
#include "ngx_http_wasm_api.h"
#include "ngx_http_wasm_module.h"
#include "ngx_http_wasm_state.h"
#include "ngx_http_wasm_map.h"
#include "ngx_http_wasm_call.h"
#include "ngx_http_wasm_ctx.h"
#include "proxy_wasm/proxy_wasm_map.h"


typedef struct {
Expand Down Expand Up @@ -550,8 +550,8 @@ proxy_send_http_response(int32_t res_code,
return PROXY_RESULT_INVALID_MEMORY_ACCESS;
}

ngx_http_wasm_map_init_iter(&it, p);
while (ngx_http_wasm_map_next(&it, &key, &key_len, &val, &val_len)) {
proxy_wasm_map_init_iter(&it, p);
while (proxy_wasm_map_next(&it, &key, &key_len, &val, &val_len)) {
rc = ngx_http_wasm_set_resp_header(r, key, key_len, 0, val, val_len, 0);
if (rc != NGX_OK) {
return PROXY_RESULT_BAD_ARGUMENT;
Expand Down Expand Up @@ -690,12 +690,12 @@ ngx_http_wasm_req_get_headers(ngx_http_request_t *r, int32_t addr, int32_t size_
}

/* get the data */
ngx_http_wasm_map_init_map(buf, count + PROXY_WASM_HEADER_STATIC_TABLE_ENTRIES);
ngx_http_wasm_map_init_iter(&it, buf);
proxy_wasm_map_init_map(buf, count + PROXY_WASM_HEADER_STATIC_TABLE_ENTRIES);
proxy_wasm_map_init_iter(&it, buf);

for (i = 0; i < count; i++) {
ngx_http_wasm_map_reserve(&it, &key, headers[i].key.len,
&val, headers[i].value.len);
proxy_wasm_map_reserve(&it, &key, headers[i].key.len,
&val, headers[i].value.len);
/* the header key is already lowercase */
ngx_memcpy(key, headers[i].key.data, headers[i].key.len);
ngx_memcpy(val, headers[i].value.data, headers[i].value.len);
Expand All @@ -713,8 +713,8 @@ ngx_http_wasm_req_get_headers(ngx_http_request_t *r, int32_t addr, int32_t size_
wh = &wasm_h2_header_static_table[i];
s = wh->getter(r);

ngx_http_wasm_map_reserve(&it, &key, wh->name.len,
&val, s->len);
proxy_wasm_map_reserve(&it, &key, wh->name.len,
&val, s->len);
ngx_memcpy(key, wh->name.data, wh->name.len);
ngx_memcpy(val, s->data, s->len);
}
Expand Down Expand Up @@ -811,8 +811,8 @@ ngx_http_wasm_resp_get_headers(ngx_http_request_t *r, int32_t addr, int32_t size
}

/* get the data */
ngx_http_wasm_map_init_map(buf, count);
ngx_http_wasm_map_init_iter(&it, buf);
proxy_wasm_map_init_map(buf, count);
proxy_wasm_map_init_iter(&it, buf);

for (i = 0; /* void */; i++) {

Expand All @@ -834,8 +834,8 @@ ngx_http_wasm_resp_get_headers(ngx_http_request_t *r, int32_t addr, int32_t size

/* nginx does not even bother initializing output header entry's
* "lowcase_key" field. so we cannot count on that at all. */
ngx_http_wasm_map_reserve(&it, &lowcase_key, header[i].key.len,
&val, header[i].value.len);
proxy_wasm_map_reserve(&it, &lowcase_key, header[i].key.len,
&val, header[i].value.len);
ngx_strlow((u_char *) lowcase_key, header[i].key.data, header[i].key.len);
ngx_memcpy(val, header[i].value.data, header[i].value.len);

Expand All @@ -845,31 +845,31 @@ ngx_http_wasm_resp_get_headers(ngx_http_request_t *r, int32_t addr, int32_t size
}

if (r->headers_out.content_type.len) {
ngx_http_wasm_map_reserve(&it, &lowcase_key, sizeof("content-type") - 1,
&val, r->headers_out.content_type.len);
proxy_wasm_map_reserve(&it, &lowcase_key, sizeof("content-type") - 1,
&val, r->headers_out.content_type.len);
ngx_memcpy(lowcase_key, "content-type", sizeof("content-type") - 1);
ngx_memcpy(val, r->headers_out.content_type.data, r->headers_out.content_type.len);
}

if (content_length_hdr != NULL) {
ngx_http_wasm_map_reserve(&it, &lowcase_key, sizeof("content-length") - 1,
&val, content_length_hdr_len);
proxy_wasm_map_reserve(&it, &lowcase_key, sizeof("content-length") - 1,
&val, content_length_hdr_len);
ngx_memcpy(lowcase_key, "content-length", sizeof("content-length") - 1);
ngx_memcpy(val, content_length_hdr, content_length_hdr_len);
}

if (r->headers_out.status == NGX_HTTP_SWITCHING_PROTOCOLS) {
ngx_http_wasm_map_reserve_literal(&it, "connection", "upgrade");
proxy_wasm_map_reserve_literal(&it, "connection", "upgrade");

} else if (r->keepalive) {
ngx_http_wasm_map_reserve_literal(&it, "connection", "keep-alive");
proxy_wasm_map_reserve_literal(&it, "connection", "keep-alive");

} else {
ngx_http_wasm_map_reserve_literal(&it, "connection", "close");
proxy_wasm_map_reserve_literal(&it, "connection", "close");
}

if (r->chunked) {
ngx_http_wasm_map_reserve_literal(&it, "transfer-encoding", "chunked");
proxy_wasm_map_reserve_literal(&it, "transfer-encoding", "chunked");
}

return PROXY_RESULT_OK;
Expand Down Expand Up @@ -908,13 +908,13 @@ ngx_http_wasm_http_call_resp_get_headers(ngx_http_request_t *r, int32_t addr, in
}

/* get the data */
ngx_http_wasm_map_init_map(buf, ctx->call_resp_n_header);
ngx_http_wasm_map_init_iter(&it, buf);
proxy_wasm_map_init_map(buf, ctx->call_resp_n_header);
proxy_wasm_map_init_iter(&it, buf);

for (i = 0; i < ctx->call_resp_n_header; i++) {
char *key, *val;

ngx_http_wasm_map_reserve(&it, &key, hdr[i].key.len, &val, hdr[i].value.len);
proxy_wasm_map_reserve(&it, &key, hdr[i].key.len, &val, hdr[i].value.len);
ngx_memcpy(key, hdr[i].key.data, hdr[i].key.len);
ngx_memcpy(val, hdr[i].value.data, hdr[i].value.len);
}
Expand Down
2 changes: 1 addition & 1 deletion src/http/ngx_http_wasm_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include <wasm.h>
#include <wasmtime.h>
#include <ngx_core.h>
#include "ngx_http_wasm_types.h"
#include "proxy_wasm/proxy_wasm_types.h"


#define MAX_WASM_API_ARG 12
Expand Down
10 changes: 5 additions & 5 deletions src/http/ngx_http_wasm_call.c
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#include <ngx_http.h>
#include "ngx_http_wasm_call.h"
#include "ngx_http_wasm_ctx.h"
#include "ngx_http_wasm_map.h"
#include "ngx_http_wasm_types.h"
#include "proxy_wasm/proxy_wasm_types.h"
#include "proxy_wasm/proxy_wasm_map.h"


typedef struct {
Expand Down Expand Up @@ -86,7 +86,7 @@ ngx_http_wasm_call_max_headers_count(ngx_http_request_t *r)

ctx = ngx_http_wasm_get_module_ctx(r);
callout = ctx->callout;
ngx_http_wasm_map_init_iter(&it, callout->map_data);
proxy_wasm_map_init_iter(&it, callout->map_data);

return it.len;
}
Expand All @@ -112,9 +112,9 @@ ngx_http_wasm_call_get(ngx_http_request_t *r, ngx_str_t *method, ngx_str_t *sche
*host = *callout->up;
*timeout = callout->timeout_ms;

ngx_http_wasm_map_init_iter(&it, callout->map_data);
proxy_wasm_map_init_iter(&it, callout->map_data);

while (ngx_http_wasm_map_next(&it, &key, &key_len, &val, &val_len)) {
while (proxy_wasm_map_next(&it, &key, &key_len, &val, &val_len)) {
if (key_len == 0) {
continue;
}
Expand Down
2 changes: 1 addition & 1 deletion src/http/ngx_http_wasm_ctx.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

#include <ngx_core.h>
#include "ngx_http_wasm_state.h"
#include "ngx_http_wasm_types.h"
#include "proxy_wasm/proxy_wasm_types.h"


#define PROXY_WASM_ABI_VER_010 0
Expand Down
38 changes: 0 additions & 38 deletions src/http/ngx_http_wasm_map.h

This file was deleted.

12 changes: 6 additions & 6 deletions src/http/ngx_http_wasm_map.c → src/proxy_wasm/proxy_wasm_map.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "ngx_http_wasm_map.h"
#include "proxy_wasm_map.h"


/**
Expand All @@ -10,14 +10,14 @@


void
ngx_http_wasm_map_init_map(const u_char *map_data, int32_t len)
proxy_wasm_map_init_map(const u_char *map_data, int32_t len)
{
*(int32_t *) map_data = len;
}


void
ngx_http_wasm_map_init_iter(proxy_wasm_map_iter *it, const u_char *map_data)
proxy_wasm_map_init_iter(proxy_wasm_map_iter *it, const u_char *map_data)
{
it->idx = 0;
it->len = *(int32_t *) map_data;
Expand All @@ -27,7 +27,7 @@ ngx_http_wasm_map_init_iter(proxy_wasm_map_iter *it, const u_char *map_data)


bool
ngx_http_wasm_map_next(proxy_wasm_map_iter *it, char **key, int32_t *key_len,
proxy_wasm_map_next(proxy_wasm_map_iter *it, char **key, int32_t *key_len,
char **val, int32_t *val_len)
{
if (it->idx == it->len) {
Expand All @@ -50,7 +50,7 @@ ngx_http_wasm_map_next(proxy_wasm_map_iter *it, char **key, int32_t *key_len,


bool
ngx_http_wasm_map_reserve(proxy_wasm_map_iter *it, char **key, int32_t key_len,
proxy_wasm_map_reserve(proxy_wasm_map_iter *it, char **key, int32_t key_len,
char **val, int32_t val_len)
{
if (it->idx == it->len) {
Expand All @@ -77,7 +77,7 @@ ngx_http_wasm_map_reserve(proxy_wasm_map_iter *it, char **key, int32_t key_len,


bool
ngx_http_wasm_map_reserve_literal_with_len(proxy_wasm_map_iter *it,
proxy_wasm_map_reserve_literal_with_len(proxy_wasm_map_iter *it,
const char *key, size_t key_len,
const char *val, size_t val_len)
{
Expand Down
38 changes: 38 additions & 0 deletions src/proxy_wasm/proxy_wasm_map.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#ifndef PROXY_WASM_MAP_H
#define PROXY_WASM_MAP_H
#include <stdbool.h>
#include <ngx_core.h>


typedef enum {
PROXY_MAP_TYPE_HTTP_REQUEST_HEADERS = 0,
PROXY_MAP_TYPE_HTTP_REQUEST_TRAILERS = 1,
PROXY_MAP_TYPE_HTTP_RESPONSE_HEADERS = 2,
PROXY_MAP_TYPE_HTTP_RESPONSE_TRAILERS = 3,
PROXY_MAP_TYPE_HTTP_CALL_RESPONSE_HEADERS = 6,
PROXY_MAP_TYPE_HTTP_CALL_RESPONSE_TRAILERS = 7,
} proxy_map_type_t;


typedef struct {
int32_t idx;
int32_t len;
int32_t *size_ptr;
char *data_ptr;
} proxy_wasm_map_iter;


void proxy_wasm_map_init_map(const u_char *map_data, int32_t len);
void proxy_wasm_map_init_iter(proxy_wasm_map_iter *it, const u_char *map_data);
bool proxy_wasm_map_next(proxy_wasm_map_iter *it, char **key, int32_t *key_len,
char **val, int32_t *val_len);
bool proxy_wasm_map_reserve(proxy_wasm_map_iter *it, char **key, int32_t key_len,
char **val, int32_t val_len);
bool proxy_wasm_map_reserve_literal_with_len(proxy_wasm_map_iter *it,
const char *key, size_t key_len,
const char *val, size_t val_len);
#define proxy_wasm_map_reserve_literal(it, k, v) \
proxy_wasm_map_reserve_literal_with_len(it, k, sizeof((k)) - 1, v, sizeof((v)) - 1)


#endif // PROXY_WASM_MAP_H
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef NGX_HTTP_WASM_TYPES_H
#define NGX_HTTP_WASM_TYPES_H
#ifndef PROXY_WASM_TYPES_H
#define PROXY_WASM_TYPES_H


#include <ngx_core.h>
Expand Down Expand Up @@ -72,4 +72,4 @@ enum {
};


#endif // NGX_HTTP_WASM_TYPES_H
#endif // PROXY_WASM_TYPES_H