util_test.go 326 B

123456789101112131415161718
  1. package httpx
  2. import (
  3. "net/http"
  4. "strings"
  5. "testing"
  6. "github.com/stretchr/testify/assert"
  7. )
  8. func TestGetRemoteAddr(t *testing.T) {
  9. host := "8.8.8.8"
  10. r, err := http.NewRequest(http.MethodGet, "/", strings.NewReader(""))
  11. assert.Nil(t, err)
  12. r.Header.Set(xForwardFor, host)
  13. assert.Equal(t, host, GetRemoteAddr(r))
  14. }