executor: brand outgoing HTTP requests, closes #13

This commit is contained in:
Cadey Ratio 2019-12-13 12:01:48 +00:00
parent 0f09e314b2
commit 3024971fdf
3 changed files with 22 additions and 1 deletions

View File

@ -5,6 +5,7 @@ import (
"fmt"
"io"
"log"
"net/http"
"os"
"time"
@ -63,6 +64,7 @@ func Run(c Config) (*Result, error) {
p.Stdout = c.Stdout
p.Stderr = c.Stderr
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}
vm, err := exec.NewVirtualMachine(c.Binary, c.VMConfig, p, gp)
@ -95,3 +97,20 @@ func Run(c Config) (*Result, error) {
StartTime: begin,
}, 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
View File

@ -21,6 +21,6 @@ require (
github.com/rogpeppe/go-internal v1.5.0
golang.org/x/crypto v0.0.0-20190923035154-9ee001bba392
within.website/ln v0.7.0
within.website/olin v0.3.0
within.website/olin v0.3.1
within.website/x v1.2.1
)

2
go.sum
View File

@ -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.3.0 h1:uicBbzY0Tlez2zZxlyjYnq+J/1nGAv5wC2XtldLwfek=
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/go.mod h1:f6yg4hO/pprWxgRNHxKZU0Z/aKCsZq+WLg3iR8n1V6U=