Send HTTP Basic Auth in request to origin

Convert a password sent by the client in the querystring into a Authorization header to your origin server.

VCL

Use this solution in your VCL service (click RUN below to test this solution or clone it to make changes):

Compute@Edge

Use this solution in your Compute@Edge service:

  1. Rust
// create a HashMap with a query string provided
let mut qs_map: std::collections::HashMap<String, String> = req.get_query()?;
// if we have the query param we need
if qs_map.contains_key("user") && qs_map.contains_key("pw") {
let auth_basic = format!(
"Basic {}",
base64::encode(format!(
"{}:{}",
qs_map.remove("user").unwrap(),
qs_map.remove("pw").unwrap()
))
);
// - repopulate query string with anything remaining
req.set_query(&qs_map)?;
// Add Authorization header
req.set_header(header::AUTHORIZATION, auth_basic);
}