Crates.io | fake_headers |
lib.rs | fake_headers |
version | 0.0.5 |
source | src |
created_at | 2023-09-08 10:02:35.444607 |
updated_at | 2023-09-08 11:14:48.359146 |
description | Generate fake HTTP headers for your HTTP requests. |
homepage | https://github.com/shhossain/rust-fake-headers |
repository | https://github.com/shhossain/rust-fake-headers |
max_upload_size | |
id | 966896 |
size | 11,035 |
This is created from python fake_headers
module. It generates random user-agent and other headers for your http requests.
use fake_headers::Headers;
use reqwest::header::HeaderMap;
fn main() {
let fheaders = Headers {
browser: 'chrome', # `chrome`, `firefox` or `opera`
os: `win`, # `win`, `linux` or `mac`
headers: true,
};
let generated_headers = fheaders.generate();
println!("{:?}", generated_headers);
// or get random header
let random_header = Headers::default().generate();
println!("{:?}", random_header);
// add headers to reqwest
let mut headers = reqwest::header::HeaderMap::new();
for (key, value) in random_header {
let header_name = reqwest::header::HeaderName::from_bytes(key.as_bytes()).unwrap();
let header_value = reqwest::header::HeaderValue::from_str(&value).unwrap();
headers.insert(header_name, header_value);
}
let client = reqwest::Client::builder()
.default_headers(headers)
.build()
.unwrap();
let res = client.get("https://httpbin.org/headers").send().unwrap();
println!("{:?}", res.text().unwrap());
}