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

Cannot send request with no Accept header #783

Closed
k4lizen opened this issue Sep 27, 2023 · 1 comment · Fixed by #786
Closed

Cannot send request with no Accept header #783

k4lizen opened this issue Sep 27, 2023 · 1 comment · Fixed by #786

Comments

@k4lizen
Copy link
Contributor

k4lizen commented Sep 27, 2023

From colly.go:
image

I need to send a request with no headers, but colly automatically inserts "Accept: */*" AFTER the OnRequest call. So I don't know how to affect it.

Example why I need to do this:

func thisworks() {
	client := &http.Client{}
	req, _ := http.NewRequest("GET", "https://api.yep.com/fs/2/search?client=web&gl=US&no_correct=false&q=youtube&safeSearch=off&type=web", nil)
	//req.Header.Set("Accept", "*/*")
	resp, _ := client.Do(req)

	log.Debug().Msgf("WRequest Header: %v", resp.Request.Header)
	log.Debug().Msgf("WResponse Header: %v", resp.Header)
	body, _ := ioutil.ReadAll(resp.Body)
	log.Debug().Msgf("WResponse Body: %v", string(body))
}

func thisdoesnt() {
	client := &http.Client{}
	req, _ := http.NewRequest("GET", "https://api.yep.com/fs/2/search?client=web&gl=US&no_correct=false&q=youtube&safeSearch=off&type=web", nil)
	req.Header.Set("Accept", "*/*")
	resp, _ := client.Do(req)

	log.Debug().Msgf("Request Header: %v", resp.Request.Header)
	log.Debug().Msgf("Response Header: %v", resp.Header)
	body, _ := ioutil.ReadAll(resp.Body)
	log.Debug().Msgf("Response Body: %v", string(body))
}

The two functions give different responses, the only difference being the req.Header.Set("Accept", "*/*") line. I need the response that I get when the Accept isn't passed.

The good response: ["Ok",{"results":[{"url":"https://apps.apple.com/us/app/youtube-watch-listen-stream/id544007664","title":"YouTube: Watch, Liste....
The bad response: ["Ok",{"results":[{"url":"https://www.commonsensemedia.org/website-reviews/youtube","title":"YouTube Website Review | Co...

@k4lizen
Copy link
Contributor Author

k4lizen commented Oct 3, 2023

I am currently using a fork (from the PR above^) to circumvent this issue

@WGH- WGH- closed this as completed in #786 Oct 20, 2023
WGH- pushed a commit that referenced this issue Oct 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant