tag1consulting / goose

Load testing framework, inspired by Locust
https://tag1.com/goose
Apache License 2.0
791 stars 70 forks source link

[docs] Run requests through a SOCKS proxy #490

Open ElijahLynn opened 2 years ago

ElijahLynn commented 2 years ago

This is me rubber ducking for now. I need to figure out how to run the requests through a SOCKS proxy. I gather the http lib rust uses supports this. I searched https://book.goose.rs/?search=proxy and didn't see anything so once I figure it out, I'll post here and maybe we can get it documented.

jeremyandrews commented 2 years ago

Ultimately the question is, how to use Reqwest through a SOCKS proxy: https://docs.rs/reqwest/latest/reqwest/struct.Proxy.html

ElijahLynn commented 2 years ago

Ultimately the question is, how to use Reqwest through a SOCKS proxy: https://docs.rs/reqwest/latest/reqwest/struct.Proxy.html

Thanks, this was helpful. From your lead, I then found https://docs.rs/reqwest/latest/reqwest/index.html#proxies which states that the usual HTTPS_PROXY and HTTP_PROXY environment variables can be used (export https_proxy=socks5://127.0.0.1:1086) and this almost seems to work but doesn't because DNS resolution isn't resolving through the SOCKS server, e.g. 'error trying to connect: dns error: failed to lookup address information: No address associated with hostname'.

curl works with DNS and HTTP_PROXY set though... I'll tinker some more tomorrow. I need to be 100% sure it is going through the proxy first.

edit: Oh, I had to add the socks feature to the below stanza to Cargo.toml, and run with cargo ... --features socks too.

[features]
default = ["reqwest/default-tls"]
socks = []
gaggle = ["nng"]
rustls-tls = ["reqwest/rustls-tls", "tokio-tungstenite/rustls-tls"]
jeremyandrews commented 2 years ago

It looks like you have to specify the protocol differently to route DNS, see the update to the example in the codebase in this issue: https://github.com/seanmonstar/reqwest/issues/899

ElijahLynn commented 2 years ago

Hrm, so that is what the H is for (maybe)!

Turns out I actually tried both and the most recent run was the socks5h:// scheme.

image

I'll tinker some more in a bit once my day gets going. Maybe I'll post an upstream support issue in reqwest if I can't figure it out.

ElijahLynn commented 2 years ago

W00t, I got SOCKS working and I understand Features a bit more now, I had to enable it ON reqwest, like so:

[dependencies]
goose = "^0.16"
tokio = "^1.12"
goose-eggs = "0.4"
rand = "0.8.5"
reqwest = { version = "0.11.10", features = ["socks"]}

source: https://docs.rs/reqwest/latest/reqwest/index.html#optional-features and https://doc.rust-lang.org/stable/cargo/reference/features.html#the-features-section

jeremyandrews commented 2 years ago

Perhaps you can summarize the steps required in the Goose documentation, adding to this page? https://book.goose.rs/getting-started/tips.html

jeremyandrews commented 2 years ago

Actually, it would make more sense to put it in this section, perhaps adding a new sub-page: https://book.goose.rs/config/overview.html