This repository has been archived by the owner on Aug 3, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 337
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1001 from larkin-nz/master
Added URL support for preview command
- Loading branch information
Showing
5 changed files
with
209 additions
and
52 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,60 @@ | ||
use url::Url; | ||
use uuid::Uuid; | ||
|
||
use super::http_method::HTTPMethod; | ||
|
||
pub struct RequestPayload { | ||
pub method: HTTPMethod, | ||
pub https: u8, | ||
pub session: String, | ||
pub protocol: String, | ||
pub domain: String, | ||
pub path: String, | ||
pub query: String, | ||
pub browser_url: String, | ||
pub service_url: String, | ||
pub body: Option<String>, | ||
} | ||
|
||
impl RequestPayload { | ||
pub fn create(method: HTTPMethod, url: Url, body: Option<String>) -> RequestPayload { | ||
let session = Uuid::new_v4().to_simple().to_string(); | ||
|
||
let https = if url.scheme() == "https" { 1 } else { 0 }; | ||
let protocol = format!("{}://", url.scheme()); | ||
|
||
let domain = url.domain().unwrap().to_string(); | ||
let path = url.path().to_string(); | ||
|
||
let query = match url.query() { | ||
Some(query) => format!("?{}", query), | ||
None => "".to_string(), | ||
}; | ||
|
||
let browser_url = format!("{}{}{}{}", protocol, domain, path, query); | ||
let service_url = format!( | ||
"{}{}{}", | ||
"https://00000000000000000000000000000000.cloudflareworkers.com", path, query | ||
); | ||
|
||
RequestPayload { | ||
method, | ||
https, | ||
session, | ||
protocol, | ||
domain, | ||
path, | ||
query, | ||
browser_url, | ||
service_url, | ||
body, | ||
} | ||
} | ||
|
||
pub fn cookie(&self, script_id: &String) -> String { | ||
format!( | ||
"__ew_fiddle_preview={}{}{}{}", | ||
script_id, self.session, self.https, self.domain | ||
) | ||
} | ||
} |
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
Oops, something went wrong.