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

client SetScheme and SetHostURL causing the hostname to be invalid #407

Closed
hendryang opened this issue Jan 25, 2021 · 2 comments · Fixed by #460
Closed

client SetScheme and SetHostURL causing the hostname to be invalid #407

hendryang opened this issue Jan 25, 2021 · 2 comments · Fixed by #460
Assignees
Labels

Comments

@hendryang
Copy link

See #318

I have managed to get the reproduction step. It's mainly caused by SetScheme

func TestHostURLForGH318(t *testing.T) {

        // Notice that I'm using both SetScheme and SetHostURL in order to reproduce this issue.
	client := resty.New()
	client.SetScheme("https").SetHostURL("httpbin.org")

	fmt.Println("with leading `/`")
	resp, err := client.R().Post("/post")
	fmt.Println("Error:", err)
	fmt.Println("Response:", resp)

	fmt.Println("\nwithout leading `/`")
	resp, err = client.R().Post("post")
	fmt.Println("Error:", err)
	fmt.Println("Response:", resp)

	fmt.Println()
	fmt.Println("with leading `/` on request")
	fmt.Println("with trailing `/` on host url")
	client.SetHostURL("https://httpbin.org/")
	resp, err = client.R().Post("/post")
	fmt.Println("Error:", err)
	fmt.Println("Response:", resp)
}

Error from first and second request:

with leading `/`
Error: Post "https://httpbin.org%2Fpost/httpbin.org/post": dial tcp: lookup httpbin.org/post: no such host
Response: 

without leading `/`
Error: Post "https://httpbin.org%2Fpost/httpbin.org/post": dial tcp: lookup httpbin.org/post: no such host
Response: 
@moorereason
Copy link
Contributor

client.SetScheme("https").SetHostURL("httpbin.org")

Resty should somehow do the right thing here (or at least not do the wrong thing), but the API assumes that the SetHostURL parameter will contain the scheme. Don't mix SetScheme and SetHostURL.

@jeevatkm
Copy link
Member

@hendryang I have fixed the issue. Can you please try this branch for-gh318-gh407 and share your feedback?

jeevatkm added a commit that referenced this issue Sep 16, 2021
* Addressing SetScheme option side effects on schemeless Host URL #407
* Travis ci config update and simplify composite literal
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

Successfully merging a pull request may close this issue.

3 participants