feat: support baggage propagation in httpc (#2375)

* feat: support baggage propagation in httpc

* chore: use go 1.16

* chore: use go 1.16

* chore: use go ^1.16

* chore: remove deprecated
This commit is contained in:
Kevin Wan
2022-09-10 15:18:52 +08:00
committed by GitHub
parent 590d784800
commit d935c83a54
44 changed files with 141 additions and 154 deletions

View File

@@ -6,7 +6,6 @@ import (
"encoding/base64"
"fmt"
"io"
"io/ioutil"
"log"
"net/http"
"net/http/httptest"
@@ -64,7 +63,7 @@ type requestSettings struct {
}
func init() {
log.SetOutput(ioutil.Discard)
log.SetOutput(io.Discard)
}
func TestContentSecurityHandler(t *testing.T) {
@@ -374,13 +373,13 @@ func buildRequest(rs requestSettings) (*http.Request, error) {
}
func createTempFile(body []byte) (string, error) {
tmpFile, err := ioutil.TempFile(os.TempDir(), "go-unit-*.tmp")
tmpFile, err := os.CreateTemp(os.TempDir(), "go-unit-*.tmp")
if err != nil {
return "", err
}
tmpFile.Close()
err = ioutil.WriteFile(tmpFile.Name(), body, os.ModePerm)
err = os.WriteFile(tmpFile.Name(), body, os.ModePerm)
if err != nil {
return "", err
}

View File

@@ -6,7 +6,6 @@ import (
"encoding/base64"
"errors"
"io"
"io/ioutil"
"net"
"net/http"
@@ -51,7 +50,7 @@ func decryptBody(key []byte, r *http.Request) error {
content = make([]byte, r.ContentLength)
_, err = io.ReadFull(r.Body, content)
} else {
content, err = ioutil.ReadAll(io.LimitReader(r.Body, maxBytes))
content, err = io.ReadAll(io.LimitReader(r.Body, maxBytes))
}
if err != nil {
return err
@@ -69,7 +68,7 @@ func decryptBody(key []byte, r *http.Request) error {
var buf bytes.Buffer
buf.Write(output)
r.Body = ioutil.NopCloser(&buf)
r.Body = io.NopCloser(&buf)
return nil
}

View File

@@ -3,7 +3,7 @@ package handler
import (
"bytes"
"encoding/base64"
"io/ioutil"
"io"
"log"
"math/rand"
"net/http"
@@ -22,7 +22,7 @@ const (
var aesKey = []byte(`PdSgVkYp3s6v9y$B&E)H+MbQeThWmZq4`)
func init() {
log.SetOutput(ioutil.Discard)
log.SetOutput(io.Discard)
}
func TestCryptionHandlerGet(t *testing.T) {
@@ -50,7 +50,7 @@ func TestCryptionHandlerPost(t *testing.T) {
req := httptest.NewRequest(http.MethodPost, "/any", &buf)
handler := CryptionHandler(aesKey)(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
body, err := ioutil.ReadAll(r.Body)
body, err := io.ReadAll(r.Body)
assert.Nil(t, err)
assert.Equal(t, reqText, string(body))

View File

@@ -2,7 +2,7 @@ package handler
import (
"bytes"
"io/ioutil"
"io"
"net/http"
"net/http/httptest"
"strings"
@@ -19,7 +19,7 @@ func TestGunzipHandler(t *testing.T) {
var wg sync.WaitGroup
wg.Add(1)
handler := GunzipHandler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
body, err := ioutil.ReadAll(r.Body)
body, err := io.ReadAll(r.Body)
assert.Nil(t, err)
assert.Equal(t, string(body), message)
wg.Done()
@@ -39,7 +39,7 @@ func TestGunzipHandler_NoGzip(t *testing.T) {
var wg sync.WaitGroup
wg.Add(1)
handler := GunzipHandler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
body, err := ioutil.ReadAll(r.Body)
body, err := io.ReadAll(r.Body)
assert.Nil(t, err)
assert.Equal(t, string(body), message)
wg.Done()

View File

@@ -7,7 +7,6 @@ import (
"errors"
"fmt"
"io"
"io/ioutil"
"net"
"net/http"
"net/http/httputil"
@@ -180,7 +179,7 @@ func logBrief(r *http.Request, code int, timer *utils.ElapsedTimer, logs *intern
if !ok {
fullReq := dumpRequest(r)
limitReader := io.LimitReader(strings.NewReader(fullReq), limitBodyBytes)
body, err := ioutil.ReadAll(limitReader)
body, err := io.ReadAll(limitReader)
if err != nil {
buf.WriteString(fmt.Sprintf("\n%s", fullReq))
} else {

View File

@@ -3,7 +3,6 @@ package handler
import (
"bytes"
"io"
"io/ioutil"
"log"
"net/http"
"net/http/httptest"
@@ -15,7 +14,7 @@ import (
)
func init() {
log.SetOutput(ioutil.Discard)
log.SetOutput(io.Discard)
}
func TestLogHandler(t *testing.T) {
@@ -55,7 +54,7 @@ func TestLogHandlerVeryLong(t *testing.T) {
req := httptest.NewRequest(http.MethodPost, "http://localhost", &buf)
handler := LogHandler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
r.Context().Value(internal.LogContext).(*internal.LogCollector).Append("anything")
io.Copy(ioutil.Discard, r.Body)
io.Copy(io.Discard, r.Body)
w.Header().Set("X-Test", "test")
w.WriteHeader(http.StatusServiceUnavailable)
_, err := w.Write([]byte("content"))

View File

@@ -1,7 +1,7 @@
package handler
import (
"io/ioutil"
"io"
"log"
"net/http"
"net/http/httptest"
@@ -15,7 +15,7 @@ import (
const conns = 4
func init() {
log.SetOutput(ioutil.Discard)
log.SetOutput(io.Discard)
}
func TestMaxConnsHandler(t *testing.T) {

View File

@@ -1,7 +1,7 @@
package handler
import (
"io/ioutil"
"io"
"log"
"net/http"
"net/http/httptest"
@@ -11,7 +11,7 @@ import (
)
func init() {
log.SetOutput(ioutil.Discard)
log.SetOutput(io.Discard)
}
func TestWithPanic(t *testing.T) {

View File

@@ -1,7 +1,7 @@
package handler
import (
"io/ioutil"
"io"
"log"
"net/http"
"net/http/httptest"
@@ -13,7 +13,7 @@ import (
)
func init() {
log.SetOutput(ioutil.Discard)
log.SetOutput(io.Discard)
}
func TestSheddingHandlerAccept(t *testing.T) {

View File

@@ -2,7 +2,7 @@ package handler
import (
"context"
"io/ioutil"
"io"
"log"
"net/http"
"net/http/httptest"
@@ -13,7 +13,7 @@ import (
)
func init() {
log.SetOutput(ioutil.Discard)
log.SetOutput(io.Discard)
}
func TestTimeout(t *testing.T) {