mirror of
https://github.com/Orange-OpenSource/hurl.git
synced 2024-11-26 00:22:10 +03:00
Add application/json Content-Type header for GraphQL queries.
This commit is contained in:
parent
2242c8ba0d
commit
0aa0568c91
@ -1,4 +1,4 @@
|
||||
curl 'http://localhost:8000/multilines/plain-text' -H 'Content-Type:' --data $'line1\nline2\nline3\n'
|
||||
curl 'http://localhost:8000/multilines/json' -H 'Content-Type:' --data $'{\n "foo": "bar"\n "baz": 123456\n}\n'
|
||||
curl 'http://localhost:8000/multilines/xml' -H 'Content-Type:' --data $'<?xml version="1.0"?>\n<catalog>\n <book id="bk101">\n <author>Gambardella, Matthew</author>\n <title>XML Developer\'s Guide</title>\n <genre>Computer</genre>\n <price>44.95</price>\n <publish_date>2000-10-01</publish_date>\n <description>An in-depth look at creating applications\n with XML.</description>\n </book>\n</catalog>\n'
|
||||
curl 'http://localhost:8000/multilines/graphql' -H 'Content-Type:' --data '{"query":"{\n hero {\n name\n # Queries can have comments!\n friends {\n name\n }\n }\n}\n"}'
|
||||
curl 'http://localhost:8000/multilines/json' -H 'Content-Type: application/json' --data $'{\n "foo": "bar"\n "baz": 123456\n}\n'
|
||||
curl 'http://localhost:8000/multilines/xml' -H 'Content-Type: application/xml' --data $'<?xml version="1.0"?>\n<catalog>\n <book id="bk101">\n <author>Gambardella, Matthew</author>\n <title>XML Developer\'s Guide</title>\n <genre>Computer</genre>\n <price>44.95</price>\n <publish_date>2000-10-01</publish_date>\n <description>An in-depth look at creating applications\n with XML.</description>\n </book>\n</catalog>\n'
|
||||
curl 'http://localhost:8000/multilines/graphql' -H 'Content-Type: application/json' --data '{"query":"{\n hero {\n name\n # Queries can have comments!\n friends {\n name\n }\n }\n}"}'
|
||||
|
@ -125,7 +125,7 @@
|
||||
<span class="line"></span><span class="comment"># Different ways of testing body response:</span>
|
||||
<span class="line"></span><span class="comment"># with explicit asserts:</span>
|
||||
<span class="line section-header">[Asserts]</span>
|
||||
<span class="line"><span class="query-type">body</span> <span class="predicate-type">==</span> <span class="string">"{\"query\":\"{\\n hero {\\n name\\n # Queries can have comments!\\n friends {\\n name\\n }\\n }\\n}\\n\"}"</span></span>
|
||||
<span class="line"><span class="query-type">body</span> <span class="predicate-type">==</span> <span class="string">"{\"query\":\"{\\n hero {\\n name\\n # Queries can have comments!\\n friends {\\n name\\n }\\n }\\n}\"}"</span></span>
|
||||
<span class="line"><span class="query-type">body</span> <span class="predicate-type">==</span> <span class="multiline"><span class="line">```graphql</span>
|
||||
<span class="line">{</span>
|
||||
<span class="line"> hero {</span>
|
||||
|
@ -125,7 +125,7 @@ HTTP 200
|
||||
# Different ways of testing body response:
|
||||
# with explicit asserts:
|
||||
[Asserts]
|
||||
body == "{\"query\":\"{\\n hero {\\n name\\n # Queries can have comments!\\n friends {\\n name\\n }\\n }\\n}\\n\"}"
|
||||
body == "{\"query\":\"{\\n hero {\\n name\\n # Queries can have comments!\\n friends {\\n name\\n }\\n }\\n}\"}"
|
||||
body == ```graphql
|
||||
{
|
||||
hero {
|
||||
|
@ -1 +1 @@
|
||||
{"entries":[{"request":{"method":"POST","url":"http://localhost:8000/multilines/plain-text","body":{"type":"multiline-string","value":"line1\nline2\nline3\n"}},"response":{"status":200,"asserts":[{"query":{"type":"body"},"predicate":{"type":"equal","value":"line1\nline2\nline3\n"}},{"query":{"type":"body"},"predicate":{"type":"equal","value":"line1\nline2\nline3\n"}}],"body":{"type":"multiline-string","value":"line1\nline2\nline3\n"}}},{"request":{"method":"POST","url":"http://localhost:8000/multilines/json","body":{"type":"json","value":"{\n \"foo\": \"bar\"\n \"baz\": 123456\n}\n"}},"response":{"status":200,"asserts":[{"query":{"type":"body"},"predicate":{"type":"equal","value":"{\n \"foo\": \"bar\"\n \"baz\": 123456\n}\n"}},{"query":{"type":"body"},"predicate":{"type":"equal","value":"{\n \"foo\": \"bar\"\n \"baz\": 123456\n}\n"}}],"body":{"type":"json","value":"{\n \"foo\": \"bar\"\n \"baz\": 123456\n}\n"}}},{"request":{"method":"POST","url":"http://localhost:8000/multilines/xml","body":{"type":"xml","value":"<?xml version=\"1.0\"?>\n<catalog>\n <book id=\"bk101\">\n <author>Gambardella, Matthew</author>\n <title>XML Developer's Guide</title>\n <genre>Computer</genre>\n <price>44.95</price>\n <publish_date>2000-10-01</publish_date>\n <description>An in-depth look at creating applications\n with XML.</description>\n </book>\n</catalog>\n"}},"response":{"status":200,"asserts":[{"query":{"type":"body"},"predicate":{"type":"equal","value":"<?xml version=\"1.0\"?>\n<catalog>\n <book id=\"bk101\">\n <author>Gambardella, Matthew</author>\n <title>XML Developer's Guide</title>\n <genre>Computer</genre>\n <price>44.95</price>\n <publish_date>2000-10-01</publish_date>\n <description>An in-depth look at creating applications\n with XML.</description>\n </book>\n</catalog>\n"}},{"query":{"type":"body"},"predicate":{"type":"equal","value":"<?xml version=\"1.0\"?>\n<catalog>\n <book id=\"bk101\">\n <author>Gambardella, Matthew</author>\n <title>XML Developer's Guide</title>\n <genre>Computer</genre>\n <price>44.95</price>\n <publish_date>2000-10-01</publish_date>\n <description>An in-depth look at creating applications\n with XML.</description>\n </book>\n</catalog>\n"}}],"body":{"type":"xml","value":"<?xml version=\"1.0\"?>\n<catalog>\n <book id=\"bk101\">\n <author>Gambardella, Matthew</author>\n <title>XML Developer's Guide</title>\n <genre>Computer</genre>\n <price>44.95</price>\n <publish_date>2000-10-01</publish_date>\n <description>An in-depth look at creating applications\n with XML.</description>\n </book>\n</catalog>\n"}}},{"request":{"method":"POST","url":"http://localhost:8000/multilines/graphql","body":{"type":"graphql","value":"{\n hero {\n name\n # Queries can have comments!\n friends {\n name\n }\n }\n}\n"}},"response":{"status":200,"asserts":[{"query":{"type":"body"},"predicate":{"type":"equal","value":"{\"query\":\"{\\n hero {\\n name\\n # Queries can have comments!\\n friends {\\n name\\n }\\n }\\n}\\n\"}"}},{"query":{"type":"body"},"predicate":{"type":"equal","value":"{\n hero {\n name\n # Queries can have comments!\n friends {\n name\n }\n }\n}\n"}}],"body":{"type":"graphql","value":"{\n hero {\n name\n # Queries can have comments!\n friends {\n name\n }\n }\n}\n"}}}]}
|
||||
{"entries":[{"request":{"method":"POST","url":"http://localhost:8000/multilines/plain-text","body":{"type":"multiline-string","value":"line1\nline2\nline3\n"}},"response":{"status":200,"asserts":[{"query":{"type":"body"},"predicate":{"type":"equal","value":"line1\nline2\nline3\n"}},{"query":{"type":"body"},"predicate":{"type":"equal","value":"line1\nline2\nline3\n"}}],"body":{"type":"multiline-string","value":"line1\nline2\nline3\n"}}},{"request":{"method":"POST","url":"http://localhost:8000/multilines/json","body":{"type":"json","value":"{\n \"foo\": \"bar\"\n \"baz\": 123456\n}\n"}},"response":{"status":200,"asserts":[{"query":{"type":"body"},"predicate":{"type":"equal","value":"{\n \"foo\": \"bar\"\n \"baz\": 123456\n}\n"}},{"query":{"type":"body"},"predicate":{"type":"equal","value":"{\n \"foo\": \"bar\"\n \"baz\": 123456\n}\n"}}],"body":{"type":"json","value":"{\n \"foo\": \"bar\"\n \"baz\": 123456\n}\n"}}},{"request":{"method":"POST","url":"http://localhost:8000/multilines/xml","body":{"type":"xml","value":"<?xml version=\"1.0\"?>\n<catalog>\n <book id=\"bk101\">\n <author>Gambardella, Matthew</author>\n <title>XML Developer's Guide</title>\n <genre>Computer</genre>\n <price>44.95</price>\n <publish_date>2000-10-01</publish_date>\n <description>An in-depth look at creating applications\n with XML.</description>\n </book>\n</catalog>\n"}},"response":{"status":200,"asserts":[{"query":{"type":"body"},"predicate":{"type":"equal","value":"<?xml version=\"1.0\"?>\n<catalog>\n <book id=\"bk101\">\n <author>Gambardella, Matthew</author>\n <title>XML Developer's Guide</title>\n <genre>Computer</genre>\n <price>44.95</price>\n <publish_date>2000-10-01</publish_date>\n <description>An in-depth look at creating applications\n with XML.</description>\n </book>\n</catalog>\n"}},{"query":{"type":"body"},"predicate":{"type":"equal","value":"<?xml version=\"1.0\"?>\n<catalog>\n <book id=\"bk101\">\n <author>Gambardella, Matthew</author>\n <title>XML Developer's Guide</title>\n <genre>Computer</genre>\n <price>44.95</price>\n <publish_date>2000-10-01</publish_date>\n <description>An in-depth look at creating applications\n with XML.</description>\n </book>\n</catalog>\n"}}],"body":{"type":"xml","value":"<?xml version=\"1.0\"?>\n<catalog>\n <book id=\"bk101\">\n <author>Gambardella, Matthew</author>\n <title>XML Developer's Guide</title>\n <genre>Computer</genre>\n <price>44.95</price>\n <publish_date>2000-10-01</publish_date>\n <description>An in-depth look at creating applications\n with XML.</description>\n </book>\n</catalog>\n"}}},{"request":{"method":"POST","url":"http://localhost:8000/multilines/graphql","body":{"type":"graphql","value":"{\n hero {\n name\n # Queries can have comments!\n friends {\n name\n }\n }\n}\n"}},"response":{"status":200,"asserts":[{"query":{"type":"body"},"predicate":{"type":"equal","value":"{\"query\":\"{\\n hero {\\n name\\n # Queries can have comments!\\n friends {\\n name\\n }\\n }\\n}\"}"}},{"query":{"type":"body"},"predicate":{"type":"equal","value":"{\n hero {\n name\n # Queries can have comments!\n friends {\n name\n }\n }\n}\n"}}],"body":{"type":"graphql","value":"{\n hero {\n name\n # Queries can have comments!\n friends {\n name\n }\n }\n}\n"}}}]}
|
||||
|
@ -1 +1 @@
|
||||
{"query":"{\n hero {\n name\n # Queries can have comments!\n friends {\n name\n }\n }\n}\n"}
|
||||
{"query":"{\n hero {\n name\n # Queries can have comments!\n friends {\n name\n }\n }\n}"}
|
@ -46,7 +46,7 @@ def multilines_xml():
|
||||
|
||||
@app.route("/multilines/graphql", methods=["POST"])
|
||||
def multilines_graphql():
|
||||
expected_body = r'{"query":"{\n hero {\n name\n # Queries can have comments!\n friends {\n name\n }\n }\n}\n"}'
|
||||
expected_body = r'{"query":"{\n hero {\n name\n # Queries can have comments!\n friends {\n name\n }\n }\n}"}'
|
||||
body_in = request.data.decode("utf-8")
|
||||
assert expected_body == body_in
|
||||
return expected_body
|
||||
|
@ -402,11 +402,17 @@ impl Client {
|
||||
list.append(format!("Content-Type: {}", s).as_str())
|
||||
.unwrap();
|
||||
} else {
|
||||
list.append("Content-Type:").unwrap(); // remove header Content-Type
|
||||
// We remove default Content-Type headers added by curl because we want
|
||||
// to explicitly manage this header.
|
||||
// For instance, with --data option, curl will send a 'Content-type: application/x-www-form-urlencoded'
|
||||
// header.
|
||||
list.append("Content-Type:").unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
if request.get_header_values("Expect").is_empty() {
|
||||
// We remove default Expect headers added by curl because we want
|
||||
// to explicitly manage this header.
|
||||
list.append("Expect:").unwrap(); // remove header Expect
|
||||
}
|
||||
|
||||
|
@ -38,7 +38,7 @@ pub fn eval_multiline(
|
||||
}
|
||||
MultilineString::GraphQl(GraphQl { value, .. }) => {
|
||||
let query = eval_template(value, variables)?;
|
||||
let body = json!({ "query": query });
|
||||
let body = json!({ "query": query.trim() });
|
||||
Ok(body.to_string())
|
||||
}
|
||||
}
|
||||
|
@ -103,13 +103,16 @@ pub fn eval_request(
|
||||
} else if !multipart.is_empty() {
|
||||
Some("multipart/form-data".to_string())
|
||||
} else if let Some(Body {
|
||||
value: Bytes::Json { .. },
|
||||
value:
|
||||
Bytes::Json { .. }
|
||||
| Bytes::MultilineString(MultilineString::GraphQl(..))
|
||||
| Bytes::MultilineString(MultilineString::Json(..)),
|
||||
..
|
||||
}) = request.body
|
||||
{
|
||||
Some("application/json".to_string())
|
||||
} else if let Some(Body {
|
||||
value: Bytes::Xml { .. },
|
||||
value: Bytes::Xml { .. } | Bytes::MultilineString(MultilineString::Xml(..)),
|
||||
..
|
||||
}) = request.body
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user