-
-
Notifications
You must be signed in to change notification settings - Fork 91
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: refactored http placeholders parsing
- Loading branch information
1 parent
b45101b
commit 0978500
Showing
3 changed files
with
147 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
use crate::creds::Credentials; | ||
|
||
const USERNAME: &str = "{USERNAME}"; | ||
const PASSWORD: &str = "{PASSWORD}"; | ||
const PAYLOAD: &str = "{PAYLOAD}"; | ||
|
||
pub(crate) fn interpolate(data: &str, creds: &Credentials) -> String { | ||
let mut parsed = data.to_owned(); | ||
|
||
// undo query encoding of interpolation params | ||
for placeholder in vec![USERNAME, PASSWORD, PAYLOAD] { | ||
let encoded_lwr = placeholder.replace("{", "%7b").replace("}", "%7d"); | ||
let encoded_upr = placeholder.replace("{", "%7B").replace("}", "%7D"); | ||
|
||
parsed = parsed | ||
.replace(&encoded_lwr, placeholder) | ||
.replace(&encoded_upr, placeholder); | ||
} | ||
|
||
// interpolate placeholders | ||
parsed | ||
.replace(USERNAME, &creds.username) | ||
.replace(PAYLOAD, &creds.username) | ||
.replace(PASSWORD, &creds.password) | ||
} |