@@ -29,34 +29,33 @@ func main() {
29
29
proxywasm .SetVMContext (& vmContext {})
30
30
}
31
31
32
- type vmContext struct {}
33
-
34
- // Implement types.VMContext.
35
- func (* vmContext ) OnVMStart (vmConfigurationSize int ) types.OnVMStartStatus {
36
- return types .OnVMStartStatusOK
32
+ type vmContext struct {
33
+ // Embed the default VM context here,
34
+ // so that we don't need to reimplement all the methods.
35
+ types.DefaultVMContext
37
36
}
38
37
39
- // Implement types.VMContext .
38
+ // Override types.DefaultVMContext .
40
39
func (* vmContext ) NewPluginContext (contextID uint32 ) types.PluginContext {
41
40
return & pluginContext {}
42
41
}
43
42
44
43
type pluginContext struct {
45
- // Embed the default root context here,
44
+ // Embed the default plugin context here,
46
45
// so that we don't need to reimplement all the methods.
47
46
types.DefaultPluginContext
48
47
shouldEchoBody bool
49
48
}
50
49
51
- // Override DefaultPluginContext.
50
+ // Override types. DefaultPluginContext.
52
51
func (ctx * pluginContext ) NewHttpContext (contextID uint32 ) types.HttpContext {
53
52
if ctx .shouldEchoBody {
54
53
return & echoBodyContext {}
55
54
}
56
55
return & setBodyContext {}
57
56
}
58
57
59
- // Override DefaultPluginContext.
58
+ // Override types. DefaultPluginContext.
60
59
func (ctx * pluginContext ) OnPluginStart (pluginConfigurationSize int ) types.OnPluginStartStatus {
61
60
data , err := proxywasm .GetPluginConfiguration (pluginConfigurationSize )
62
61
if err != nil {
@@ -74,7 +73,7 @@ type setBodyContext struct {
74
73
bufferOperation string
75
74
}
76
75
77
- // Override DefaultHttpContext.
76
+ // Override types. DefaultHttpContext.
78
77
func (ctx * setBodyContext ) OnHttpRequestHeaders (numHeaders int , endOfStream bool ) types.Action {
79
78
if _ , err := proxywasm .GetHttpRequestHeader ("content-length" ); err != nil {
80
79
if err := proxywasm .SendHttpResponse (400 , nil , []byte ("content must be provided" )); err != nil {
@@ -100,7 +99,7 @@ func (ctx *setBodyContext) OnHttpRequestHeaders(numHeaders int, endOfStream bool
100
99
return types .ActionContinue
101
100
}
102
101
103
- // Override DefaultHttpContext.
102
+ // Override types. DefaultHttpContext.
104
103
func (ctx * setBodyContext ) OnHttpRequestBody (bodySize int , endOfStream bool ) types.Action {
105
104
ctx .totalRequestBodySize += bodySize
106
105
if ! endOfStream {
@@ -131,13 +130,13 @@ func (ctx *setBodyContext) OnHttpRequestBody(bodySize int, endOfStream bool) typ
131
130
}
132
131
133
132
type echoBodyContext struct {
134
- // mbed the default root context
133
+ // mbed the default plugin context
135
134
// so that you don't need to reimplement all the methods by yourself.
136
135
types.DefaultHttpContext
137
136
totalRequestBodySize int
138
137
}
139
138
140
- // Override DefaultHttpContext.
139
+ // Override types. DefaultHttpContext.
141
140
func (ctx * echoBodyContext ) OnHttpRequestBody (bodySize int , endOfStream bool ) types.Action {
142
141
ctx .totalRequestBodySize += bodySize
143
142
if ! endOfStream {
0 commit comments