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

Specify host header and send request against IP #581

Closed
ecc256 opened this issue May 4, 2017 · 6 comments
Closed

Specify host header and send request against IP #581

ecc256 opened this issue May 4, 2017 · 6 comments

Comments

@ecc256
Copy link

ecc256 commented May 4, 2017

Is there a way to specify host header and send request against IP similar to this:

txheaders = { 'User-Agent': UA, "Host": nohttp_url }
robots = urllib2.Request("http://" + ip  + "/robots.txt", txdata, txheaders)

Our main site has single IP and distinguish virtual sites via host header.
There are multiple web servers behind load balancer.
I need to run test against internal (particular web server) IP or external (load-balanced) IP

I guess, I can use custom DNS to map everything to IP I need, but workstation I run tests from is used for many other things...

Could somebody clarify why User-Agent header works, but Host is ignored, please?
Is there another workaround without custom DNS?

I need smth. like:
locust --host=http://IP --no-web

h = {
"Host": "my.name.com",
"User-Agent":"locust",
}
self.client.get("/", headers=h)
@aimer1124
Copy link

aimer1124 commented Jun 20, 2017

h = """{
"Host": "my.name.com",
"User-Agent":"locust",
}
"""
self.client.get("/", headers=h)

Try this.

@cgoldberg
Copy link
Member

@aimer1124 how does that help? The headers kwarg accepts a python dictionary, not a json string.

@aimer1124
Copy link

@ecc256 @cgoldberg
Sorry, I can't got the issue correctly, please ignore my replay above.

@maximv-q4
Copy link

maximv-q4 commented Sep 1, 2017

@ecc256 were you able to achieve that?

@ecc256
Copy link
Author

ecc256 commented Jul 3, 2018

Just tested - Locust 0.8.1 sends host header properly.

@divyatv
Copy link

divyatv commented Dec 12, 2019

I used to get 401 errors, while using python Locust for a load test- but wasn't able to figure out how to send Authentication Type= Preemptive in the headers. But this clue helped and was able to figure out the solution.

h={'Authorization': 'Basic PUTKEYHERE'}
self.client.get("/ ", headers=h)

Thank you!

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

No branches or pull requests

5 participants