Skip to content

Commit

Permalink
update js_request
Browse files Browse the repository at this point in the history
  • Loading branch information
tusharmath committed May 4, 2024
1 parent be31865 commit 1b5c683
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/cli/javascript/js_request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ use crate::is_default;
pub struct JsRequest(reqwest::Request);

impl JsRequest {
pub fn uri(&self) -> Uri {
fn uri(&self) -> Uri {
self.0.url().into()
}

pub fn method(&self) -> String {
fn method(&self) -> String {
self.0.method().to_string()
}

pub fn headers(&self) -> anyhow::Result<BTreeMap<String, String>> {
fn headers(&self) -> anyhow::Result<BTreeMap<String, String>> {
let headers = self.0.headers();
let mut map = BTreeMap::new();
for (k, v) in headers.iter() {
Expand All @@ -31,7 +31,7 @@ impl JsRequest {
Ok(map)
}

pub fn body(&self) -> Option<String> {
fn body(&self) -> Option<String> {
if let Some(body) = self.0.body() {
let bytes = body.as_bytes()?;
Some(String::from_utf8_lossy(bytes).to_string())
Expand All @@ -40,6 +40,7 @@ impl JsRequest {
}
}
}

impl TryFrom<&reqwest::Request> for JsRequest {
type Error = anyhow::Error;

Expand All @@ -56,6 +57,7 @@ impl From<JsRequest> for reqwest::Request {
val.0
}
}

impl<'js> IntoJs<'js> for JsRequest {
fn into_js(self, ctx: &rquickjs::Ctx<'js>) -> rquickjs::Result<rquickjs::Value<'js>> {
let object = rquickjs::Object::new(ctx.clone())?;
Expand Down

0 comments on commit 1b5c683

Please sign in to comment.