executor: brand outgoing HTTP requests, closes #13
This commit is contained in:
parent
0f09e314b2
commit
3024971fdf
|
@ -5,6 +5,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"log"
|
"log"
|
||||||
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
@ -63,6 +64,7 @@ func Run(c Config) (*Result, error) {
|
||||||
p.Stdout = c.Stdout
|
p.Stdout = c.Stdout
|
||||||
p.Stderr = c.Stderr
|
p.Stderr = c.Stderr
|
||||||
p.Logger = log.New(io.MultiWriter(c.LogSink, os.Stdout), c.Name+" ", log.LstdFlags)
|
p.Logger = log.New(io.MultiWriter(c.LogSink, os.Stdout), c.Name+" ", log.LstdFlags)
|
||||||
|
p.HC.Transport = WasmcloudBrandingTransport(c.Name, p.HC.Transport)
|
||||||
|
|
||||||
gp := &compiler.SimpleGasPolicy{GasPerInstruction: 1}
|
gp := &compiler.SimpleGasPolicy{GasPerInstruction: 1}
|
||||||
vm, err := exec.NewVirtualMachine(c.Binary, c.VMConfig, p, gp)
|
vm, err := exec.NewVirtualMachine(c.Binary, c.VMConfig, p, gp)
|
||||||
|
@ -95,3 +97,20 @@ func Run(c Config) (*Result, error) {
|
||||||
StartTime: begin,
|
StartTime: begin,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func WasmcloudBrandingTransport(handlerName string, rt http.RoundTripper) http.RoundTripper {
|
||||||
|
return wasmcloudBrandingTransport{
|
||||||
|
rt: rt,
|
||||||
|
handlerName: handlerName,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
type wasmcloudBrandingTransport struct {
|
||||||
|
rt http.RoundTripper
|
||||||
|
handlerName string
|
||||||
|
}
|
||||||
|
|
||||||
|
func (w wasmcloudBrandingTransport) RoundTrip(r *http.Request) (*http.Response, error) {
|
||||||
|
r.Header.Set("User-Agent", r.Header.Get("User-Agent")+" wasmcloud/"+w.handlerName)
|
||||||
|
return w.rt.RoundTrip(r)
|
||||||
|
}
|
||||||
|
|
2
go.mod
2
go.mod
|
@ -21,6 +21,6 @@ require (
|
||||||
github.com/rogpeppe/go-internal v1.5.0
|
github.com/rogpeppe/go-internal v1.5.0
|
||||||
golang.org/x/crypto v0.0.0-20190923035154-9ee001bba392
|
golang.org/x/crypto v0.0.0-20190923035154-9ee001bba392
|
||||||
within.website/ln v0.7.0
|
within.website/ln v0.7.0
|
||||||
within.website/olin v0.3.0
|
within.website/olin v0.3.1
|
||||||
within.website/x v1.2.1
|
within.website/x v1.2.1
|
||||||
)
|
)
|
||||||
|
|
2
go.sum
2
go.sum
|
@ -451,5 +451,7 @@ within.website/olin v0.2.0 h1:mfUxRVaqi2hfasOMTyuatCrVkDn6carZegFxFEqcF6w=
|
||||||
within.website/olin v0.2.0/go.mod h1:YL69W52El9WiyFH/tM1zf7+tqUGw2vLb1MGrr/WqbKo=
|
within.website/olin v0.2.0/go.mod h1:YL69W52El9WiyFH/tM1zf7+tqUGw2vLb1MGrr/WqbKo=
|
||||||
within.website/olin v0.3.0 h1:uicBbzY0Tlez2zZxlyjYnq+J/1nGAv5wC2XtldLwfek=
|
within.website/olin v0.3.0 h1:uicBbzY0Tlez2zZxlyjYnq+J/1nGAv5wC2XtldLwfek=
|
||||||
within.website/olin v0.3.0/go.mod h1:YL69W52El9WiyFH/tM1zf7+tqUGw2vLb1MGrr/WqbKo=
|
within.website/olin v0.3.0/go.mod h1:YL69W52El9WiyFH/tM1zf7+tqUGw2vLb1MGrr/WqbKo=
|
||||||
|
within.website/olin v0.3.1 h1:697dGAHeAjxTXnYR/jW2NGPAnRonnuQULtfzRfPtAF4=
|
||||||
|
within.website/olin v0.3.1/go.mod h1:YL69W52El9WiyFH/tM1zf7+tqUGw2vLb1MGrr/WqbKo=
|
||||||
within.website/x v1.2.1 h1:prNr9fWf/O7irD2hS/1na7GW/jiWdbuLnWNy1ZMkf+8=
|
within.website/x v1.2.1 h1:prNr9fWf/O7irD2hS/1na7GW/jiWdbuLnWNy1ZMkf+8=
|
||||||
within.website/x v1.2.1/go.mod h1:f6yg4hO/pprWxgRNHxKZU0Z/aKCsZq+WLg3iR8n1V6U=
|
within.website/x v1.2.1/go.mod h1:f6yg4hO/pprWxgRNHxKZU0Z/aKCsZq+WLg3iR8n1V6U=
|
||||||
|
|
Loading…
Reference in New Issue