0

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?

Chayim Friedman
  • 47,971
  • 5
  • 48
  • 77
GTP95
  • 13
  • 4
  • Looks like either the `spoof_check_secret` or `uid` contain invalid characters (only visible ASCII characters are allowed). My guess would be `spoof_check_secret`. What is that value? – Jonas Fassbender Jun 26 '23 at 17:00
  • That's not the case. I just double-checked with `xxd` and the file only contains lowecase letters and digits. In addition to that, the file ends with 0a, but I tried creating another TXT file and it also ends with 0a, so it doesn't seem to be a problem. – GTP95 Jun 26 '23 at 17:12
  • Then maybe `uid` is the culprit? – Chayim Friedman Jun 26 '23 at 18:11
  • 2
    I'm guessing `:` is not allowed. – drewtato Jun 26 '23 at 18:28
  • what is the value of uid ? it might be the issue – kumarmo2 Jun 26 '23 at 18:43
  • 3
    BTW `0a` (10, newline) is invalid according to reqwest: https://docs.rs/http/0.2.9/src/http/header/value.rs.html#588-590 – drewtato Jun 26 '23 at 18:51
  • @drewtato you were right, trimming the string after reading it from file solved the problem. Thank you, I completely missed the newline – GTP95 Jun 27 '23 at 07:51

0 Answers0