I'm new to Rust and I'm trying to use the Reqwest library to construct an HTTP request containing two custom headers and the respective values. The functions I wrote for this are as follows:
async fn oauth_request(server_address: &str, user_id: &str, spoof_check_secret: &str, uid_field_name: &str) {
let client = HTTPclient::HTTPclient::new(server_address.parse().unwrap(), uid_field_name.parse().unwrap(), spoof_check_secret.parse().unwrap());
let request_result = client
.send_auth_request(&String::from(user_id), &spoof_check_secret)
.await;
match request_result {
Ok(response) => println!("Response: {:?}", response),
Err(error) => {
println!("Error: {:?}", error);
println!("user_id: {:?}", user_id);
println!("uid_field_name: {:?}", uid_field_name);
},
}
}
pub async fn send_auth_request(&self, uid: &str, spoof_check_secret: &str) -> Result<reqwest::Response, reqwest::Error> {
let request = reqwest::Client::new()
.post(&self.url)
.header("Shib-Spoof-Check", spoof_check_secret)
.header(self.uid_field_name.clone(), uid)
.body("")
.send()
.await?;
Ok(request)
}
My problem is that instead of sending the request, I get the following output:
Error: reqwest::Error { kind: Builder, source: http::Error(InvalidHeaderValue) }
user_id: "participant:bdd25f2c-abb9-40be-ac89-5e538dad1e70"
uid_field_name: "uid"
>> Outcome: Success
>> Response succeeded.
(The last two lines are added by Rocket, to let me know that the request to the endpoint succeded).
The value I'm passing for the "user_id" header is as shown in the output, and the value for "Shib-Spoof-Check" is an alphanumeric string, where the letters are all lowercase and there are no special characters. Why is either of the two an invalid value?