2
* Licensed to the Apache Software Foundation (ASF) under one or more
3
* contributor license agreements. See the NOTICE file distributed with
4
* this work for additional information regarding copyright ownership.
5
* The ASF licenses this file to You under the Apache License, Version 2.0
6
* (the "License"); you may not use this file except in compliance with
7
* the License. You may obtain a copy of the License at
9
* http://www.apache.org/licenses/LICENSE-2.0
11
* Unless required by applicable law or agreed to in writing, software
12
* distributed under the License is distributed on an "AS IS" BASIS,
13
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
* See the License for the specific language governing permissions and
15
* limitations under the License.
23
"github.com/tetratelabs/proxy-wasm-go-sdk/proxywasm"
24
"github.com/tetratelabs/proxy-wasm-go-sdk/proxywasm/types"
27
// build main like below with proxy-wasm-go-sdk v0.0.14 which works with
28
// TinyGo 0.19.0 (which works with Go 1.16).
30
// tinygo build -o main.wasm -scheduler=none -target=wasi --no-debug -wasm-abi=generic -tags 'abi_010' ./main.go
32
// Note: Old tooling is needed because mosn.io/proxy-wasm-go-host v2 is
33
// incompatible with current proxy-wasm SDKs.
35
proxywasm.SetNewHttpContext(newHttpContext)
38
type myHttpContext struct {
39
// you must embed the default context so that you need not to re-implement all the methods by yourself
40
proxywasm.DefaultHttpContext
44
func newHttpContext(rootContextID, contextID uint32) proxywasm.HttpContext {
45
return &myHttpContext{contextID: contextID}
48
func (ctx *myHttpContext) OnHttpRequestHeaders(numHeaders int, endOfStream bool) types.Action {
50
err := proxywasm.SetHttpRequestHeader(key, strconv.Itoa(int(ctx.contextID)))
52
proxywasm.LogCritical("failed to set request header: " + key)
54
return types.ActionContinue