Use Accept request header instead of user agent to figure out non-browser clients. Funny fact, I borrowed the idea from a fork ('8a3e142cf3/router/generic.go (L33)')

This commit is contained in:
2022-04-30 17:10:22 +02:00
parent 12da27ddab
commit 9070e9a2c2
5 changed files with 124 additions and 57 deletions

View File

@ -70,16 +70,18 @@ func TestContainerIntegration(t *testing.T) {
}()
http.DefaultTransport.(*http.Transport).TLSClientConfig = &tls.Config{InsecureSkipVerify: true}
for _, url := range []string{"http://localhost:8000/json", "https://localhost:8001/json"} {
resp, _ := http.Get(url)
for _, url := range []string{"http://localhost:8000", "https://localhost:8001"} {
client := &http.Client{}
req, _ := http.NewRequest("GET", url, nil)
req.Header.Set("Accept", "application/json")
resp, _ := client.Do(req)
assert.Equal(t, 200, resp.StatusCode)
var dat router.JSONResponse
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
log.Fatal(err)
}
assert.NoError(t, json.Unmarshal(body, &dat))
assert.NoError(t, json.Unmarshal(body, &router.JSONResponse{}))
}
}