Skip to content

Commit

Permalink
- merge conflict fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
laststylebender14 committed Dec 9, 2024
1 parent 816225a commit 163de1b
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 64 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,14 @@ Index {
headers: [],
body_path: Some(
Mustache(
Mustache(
[
Expression(
[
"args",
"input",
],
),
],
),
[
Expression(
[
"args",
"input",
],
),
],
),
),
endpoint: Endpoint {
Expand Down Expand Up @@ -107,16 +105,14 @@ Index {
headers: [],
body_path: Some(
Mustache(
Mustache(
[
Expression(
[
"args",
"input",
],
),
],
),
[
Expression(
[
"args",
"input",
],
),
],
),
),
endpoint: Endpoint {
Expand Down Expand Up @@ -187,16 +183,14 @@ Index {
headers: [],
body_path: Some(
Mustache(
Mustache(
[
Expression(
[
"args",
"input",
],
),
],
),
[
Expression(
[
"args",
"input",
],
),
],
),
),
endpoint: Endpoint {
Expand Down Expand Up @@ -270,16 +264,14 @@ Index {
headers: [],
body_path: Some(
Mustache(
Mustache(
[
Expression(
[
"args",
"input",
],
),
],
),
[
Expression(
[
"args",
"input",
],
),
],
),
),
endpoint: Endpoint {
Expand Down
1 change: 0 additions & 1 deletion src/core/http/data_loader.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use std::collections::HashMap;
use std::fmt::Display;
use std::sync::Arc;
use std::time::Duration;

Expand Down
40 changes: 17 additions & 23 deletions src/core/http/request_template.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ use tailcall_hasher::TailcallHasher;
use url::Url;

use super::query_encoder::QueryEncoder;
use crate::core::blueprint::DynamicValue;
use crate::core::config::Encoding;
use crate::core::endpoint::Endpoint;
use crate::core::has_headers::HasHeaders;
Expand All @@ -16,7 +15,6 @@ use crate::core::ir::model::{CacheKey, IoId};
use crate::core::ir::DynamicRequest;
use crate::core::mustache::{Eval, Mustache, Segment};
use crate::core::path::{PathString, PathValue, ValueString};
use crate::core::serde_value_ext::ValueExt;

/// RequestTemplate is an extension of a Mustache template.
/// Various parts of the template can be written as a mustache template.
Expand All @@ -28,7 +26,7 @@ pub struct RequestTemplate {
pub query: Vec<Query>,
pub method: reqwest::Method,
pub headers: MustacheHeaders,
pub body_path: Option<DynamicValue<serde_json::Value>>,
pub body_path: Option<Mustache>,
pub endpoint: Endpoint,
pub encoding: Encoding,
pub query_encoder: QueryEncoder,
Expand Down Expand Up @@ -206,7 +204,7 @@ impl RequestTemplate {
}

pub fn with_body(mut self, body: Mustache) -> Self {
self.body_path = Some(DynamicValue::Mustache(body));
self.body_path = Some(body);
self
}
}
Expand Down Expand Up @@ -270,7 +268,7 @@ impl<Ctx: PathString + HasHeaders + PathValue> CacheKey<Ctx> for RequestTemplate
}

if let Some(body) = self.body_path.as_ref() {
body.render_value(ctx).hash(state)
body.render(ctx).hash(state)
}

let url = self.create_url(ctx).unwrap();
Expand Down Expand Up @@ -361,7 +359,6 @@ mod tests {
use serde_json::json;

use super::{Query, RequestTemplate};
use crate::core::blueprint::DynamicValue;
use crate::core::has_headers::HasHeaders;
use crate::core::json::JsonLike;
use crate::core::mustache::Mustache;
Expand Down Expand Up @@ -453,7 +450,7 @@ mod tests {
let req = request_wrapper.request();
assert_eq!(
req.url().to_string(),
"http://localhost:3000/?foo=12&baz=1&baz=2&baz=3"
"http://localhost:3000/?baz=1&baz=2&baz=3&foo=12"
);
}

Expand Down Expand Up @@ -675,41 +672,39 @@ mod tests {
fn test_body() {
let tmpl = RequestTemplate::new("http://localhost:3000")
.unwrap()
.body_path(Some(DynamicValue::Value(serde_json::Value::String(
"foo".to_string(),
))));
.body_path(Some(Mustache::parse("foo")));
let ctx = Context::default();
let body = tmpl.to_body(&ctx).unwrap();
assert_eq!(body, "\"foo\"");
assert_eq!(body, "foo");
}

#[test]
fn test_body_template() {
let tmpl = RequestTemplate::new("http://localhost:3000")
.unwrap()
.body_path(Some(DynamicValue::Mustache(Mustache::parse("{{foo.bar}}"))));
.body_path(Some(Mustache::parse("{{foo.bar}}")));
let ctx = Context::default().value(json!({
"foo": {
"bar": "baz"
}
}));
let body = tmpl.to_body(&ctx).unwrap();
assert_eq!(body, "\"baz\"");
assert_eq!(body, "baz");
}

#[test]
fn test_body_encoding_application_json() {
let tmpl = RequestTemplate::new("http://localhost:3000")
.unwrap()
.encoding(crate::core::config::Encoding::ApplicationJson)
.body_path(Some(DynamicValue::Mustache(Mustache::parse("{{foo.bar}}"))));
.body_path(Some(Mustache::parse("{{foo.bar}}")));
let ctx = Context::default().value(json!({
"foo": {
"bar": "baz"
}
}));
let body = tmpl.to_body(&ctx).unwrap();
assert_eq!(body, "\"baz\"");
assert_eq!(body, "baz");
}

mod endpoint {
Expand Down Expand Up @@ -762,7 +757,7 @@ mod tests {
assert_eq!(req.method(), reqwest::Method::POST);
assert_eq!(req.headers().get("foo").unwrap(), "abc");
let body = req.body().unwrap().as_bytes().unwrap().to_owned();
assert_eq!(body, "\"baz\"".as_bytes());
assert_eq!(body, "baz".as_bytes());
assert_eq!(req.url().to_string(), "http://localhost:3000/baz?foo=baz");
}

Expand Down Expand Up @@ -856,7 +851,6 @@ mod tests {
mod form_encoded_url {
use serde_json::json;

use crate::core::blueprint::DynamicValue;
use crate::core::http::request_template::tests::Context;
use crate::core::http::RequestTemplate;
use crate::core::mustache::Mustache;
Expand All @@ -877,9 +871,9 @@ mod tests {
fn test_with_json_template() {
let tmpl = RequestTemplate::form_encoded_url("http://localhost:3000")
.unwrap()
.body_path(Some(DynamicValue::Mustache(Mustache::parse(
.body_path(Some(Mustache::parse(
r#"{"foo": "{{baz}}"}"#,
))));
)));
let ctx = Context::default().value(json!({"baz": "baz"}));
let body = tmpl.to_body(&ctx).unwrap();
assert_eq!(body, "foo=baz");
Expand All @@ -889,7 +883,7 @@ mod tests {
fn test_with_json_body() {
let tmpl = RequestTemplate::form_encoded_url("http://localhost:3000")
.unwrap()
.body_path(Some(DynamicValue::Mustache(Mustache::parse("{{foo}}"))));
.body_path(Some(Mustache::parse("{{foo}}")));
let ctx = Context::default().value(json!({"foo": {"bar": "baz"}}));
let body = tmpl.to_body(&ctx).unwrap();
assert_eq!(body, "bar=baz");
Expand All @@ -899,7 +893,7 @@ mod tests {
fn test_with_json_body_nested() {
let tmpl = RequestTemplate::form_encoded_url("http://localhost:3000")
.unwrap()
.body_path(Some(DynamicValue::Mustache(Mustache::parse("{{a}}"))));
.body_path(Some(Mustache::parse("{{a}}")));
let ctx = Context::default()
.value(json!({"a": {"special chars": "a !@#$%^&*()<>?:{}-=1[];',./"}}));
let a = tmpl.to_body(&ctx).unwrap();
Expand All @@ -911,9 +905,9 @@ mod tests {
fn test_with_mustache_literal() {
let tmpl = RequestTemplate::form_encoded_url("http://localhost:3000")
.unwrap()
.body_path(Some(DynamicValue::Mustache(Mustache::parse(
.body_path(Some(Mustache::parse(
r#"{"foo": "bar"}"#,
))));
)));
let ctx = Context::default().value(json!({}));
let body = tmpl.to_body(&ctx).unwrap();
assert_eq!(body, r#"foo=bar"#);
Expand Down

0 comments on commit 163de1b

Please sign in to comment.