Coder Social home page Coder Social logo

wasm-nginx-module's Introduction

Status

This library is under construction. See api7#25 to know the progress.

Description

A Nginx module which tries to implement proxy wasm ABI in Nginx.

Install dependencies

  • Download the wasmtime C API package and rename it to wasmtime-c-api/, with the ./install-wasmtime.sh. Remember to add the wasmtime-c-api/lib to the library search path when you build Nginx, for instance,
export wasm_prefix=/path/to/wasm-nginx-module/wasmtime-c-api
./configure ... \
    --with-ld-opt="-Wl,-rpath,${wasm_prefix}/lib" \

Directives

wasm_vm

syntax: wasm_vm wasmtime

default: -

context: http

Select the WASM VM. Currently, only wasmtime is supported. If the directive is not set, the WASM VM won't be enabled.

Methods

Remember to set the wasm_vm directive!

load

syntax: plugin, err = proxy_wasm.load(name, path)

Load a .wasm file from the filesystem and return a WASM plugin.

local plugin, err = proxy_wasm.load("plugin","t/testdata/plugin_lifecycle/main.go.wasm")

on_configure

syntax: plugin_ctx, err = proxy_wasm.on_configure(plugin, conf)

Create a plugin ctx with the given plugin and conf.

local plugin, err = proxy_wasm.load("plugin","t/testdata/plugin_lifecycle/main.go.wasm")
if not plugin then
    ngx.log(ngx.ERR, "failed to load wasm ", err)
    return
end
local ctx, err = wasm.on_configure(plugin, '{"body":512}')
if not ctx then
    ngx.log(ngx.ERR, "failed to create plugin ctx ", err)
    return
end

on_http_request_headers

syntax: ok, err = proxy_wasm.on_http_request_headers(plugin_ctx)

Run the HTTP request headers filter in the plugin of the given plugin ctx.

local plugin, err = proxy_wasm.load("plugin","t/testdata/plugin_lifecycle/main.go.wasm")
if not plugin then
    ngx.log(ngx.ERR, "failed to load wasm ", err)
    return
end
local ctx, err = wasm.on_configure(plugin, '{"body":512}')
if not ctx then
    ngx.log(ngx.ERR, "failed to create plugin ctx ", err)
    return
end
assert(wasm.on_http_request_headers(ctx))

on_http_response_headers

syntax: ok, err = proxy_wasm.on_http_response_headers(plugin_ctx)

Run the HTTP response headers filter in the plugin of the given plugin ctx.

local plugin, err = proxy_wasm.load("plugin","t/testdata/http_lifecycle/main.go.wasm")
if not plugin then
    ngx.log(ngx.ERR, "failed to load wasm ", err)
    return
end
local ctx, err = wasm.on_configure(plugin, '{"body":512}')
if not ctx then
    ngx.log(ngx.ERR, "failed to create plugin ctx ", err)
    return
end
assert(wasm.on_http_response_headers(ctx))

proxy-wasm ABI

Implemented proxy-wasm ABI can be found in proxy_wasm_abi.

wasm-nginx-module's People

Contributors

spacewander avatar tzssangglass avatar bzp2010 avatar shuaijinchao avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.