Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to send custom header #626

Open
itziklavon opened this issue Mar 10, 2023 · 1 comment
Open

Unable to send custom header #626

itziklavon opened this issue Mar 10, 2023 · 1 comment
Labels

Comments

@itziklavon
Copy link

itziklavon commented Mar 10, 2023

Hi,
Hi, i'm getting some error when testing some code which its response with status 30X
it expects location header, but when i run tests locally, i need to ignore it, how can we do it?

currently i've defined some round tripper
but it is pretty ugly workaround, is there a simpler way?
i've tested some other web clients, on some i did not get this error, this is what i currently have defined:

	// e.g. patch the request before send it
	var roundTripper = &http.Transport{
		DialContext: (&net.Dialer{
			Timeout:   10 * time.Second,
			KeepAlive: 30 * time.Second,
		}).DialContext,
		ForceAttemptHTTP2:     false,
		MaxIdleConns:          utils.GetOrDefaultInt(viper.GetString("HTTP_CONNECTION_POOL_MAX_SIZE"), 5000),
		MaxConnsPerHost:       utils.GetOrDefaultInt(viper.GetString("HTTP_CONNECTION_POOL_MAX_SIZE_PER_HOST"), 20),
		MaxIdleConnsPerHost:   utils.GetOrDefaultInt(viper.GetString("HTTP_CONNECTION_POOL_MAX_IDLE_SIZE_PER_HOST"), 10),
		IdleConnTimeout:       90 * time.Second,
		TLSHandshakeTimeout:   10 * time.Second,
		ExpectContinueTimeout: 1 * time.Second,
	}
	resp, err := roundTripper.RoundTrip(req)

	if err == nil && resp != nil {
		switch resp.StatusCode {
		case
			http.StatusMovedPermanently,
			http.StatusSeeOther,
			http.StatusFound,
			http.StatusTemporaryRedirect,
			http.StatusPermanentRedirect:
			if len(resp.Header.Get("Location")) == 0 {
				resp.StatusCode = 406
			}
		}
	}
	return resp, err
}
@jeevatkm
Copy link
Member

@itziklavon You could make use of Redirect policy implementation.

https://pkg.go.dev/github.com/go-resty/resty/v2#readme-redirect-policy

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

2 participants