Add url query

This commit is contained in:
Fabrice Reix 2022-10-16 09:35:54 +02:00
parent 5712eacf48
commit b912a6f06c
No known key found for this signature in database
GPG Key ID: BF5213154B2E7155
11 changed files with 41 additions and 12 deletions

View File

@ -158,6 +158,7 @@ query: main-query (sp subquery)?
main-query:
status-query
| url-query
| header-query
| cookie-query
| body-query
@ -172,6 +173,8 @@ main-query:
status-query: "status"
url-query: "url"
header-query: "header" sp quoted-string
cookie-query: "cookie" sp quoted-string

View File

@ -1,5 +1,7 @@
<pre><code class="language-hurl"><span class="hurl-entry"><span class="request"><span class="line"><span class="method">GET</span> <span class="url">http://localhost:8000/redirected</span></span>
</span><span class="response"><span class="line"><span class="version">HTTP/1.0</span> <span class="number">200</span></span>
<span class="line section-header">[Asserts]</span>
<span class="line"><span class="query-type">url</span> <span class="predicate-type">==</span> <span class="string">"http://localhost:8000/redirected"</span></span>
<span class="raw"><span class="line">```Redirected```</span></span>
</span></span><span class="hurl-entry"><span class="request"><span class="line"></span>
<span class="line"></span>
@ -8,12 +10,16 @@
<span class="line"><span class="method">GET</span> <span class="url">http://localhost:8000/redirect-absolute</span></span>
</span><span class="response"><span class="line"><span class="version">HTTP/1.0</span> <span class="number">302</span></span>
<span class="line"><span class="string">Location</span><span>:</span> <span class="string">http://localhost:8000/redirected</span></span>
<span class="line section-header">[Asserts]</span>
<span class="line"><span class="query-type">url</span> <span class="predicate-type">==</span> <span class="string">"http://localhost:8000/redirect-absolute"</span></span>
</span></span><span class="hurl-entry"><span class="request"><span class="line"></span>
<span class="line"><span class="method">GET</span> <span class="url">http://localhost:8000/redirect-absolute</span></span>
<span class="line section-header">[Options]</span>
<span class="line"><span class="string">location</span><span>:</span> <span class="boolean">true</span></span>
</span><span class="response"><span class="line"></span>
<span class="line"><span class="version">HTTP/1.0</span> <span class="number">200</span></span>
<span class="line section-header">[Asserts]</span>
<span class="line"><span class="query-type">url</span> <span class="predicate-type">==</span> <span class="string">"http://localhost:8000/redirected"</span></span>
<span class="raw"><span class="line">```Redirected```</span></span>
</span></span><span class="hurl-entry"><span class="request"><span class="line"></span>
<span class="line"></span>
@ -22,16 +28,15 @@
<span class="line"><span class="method">GET</span> <span class="url">http://localhost:8000/redirect-relative</span></span>
</span><span class="response"><span class="line"><span class="version">HTTP/1.0</span> <span class="number">302</span></span>
<span class="line"><span class="string">Location</span><span>:</span> <span class="string">/redirected</span></span>
<span class="line section-header">[Asserts]</span>
<span class="line"><span class="query-type">url</span> <span class="predicate-type">==</span> <span class="string">"http://localhost:8000/redirect-relative"</span></span>
</span></span><span class="hurl-entry"><span class="request"><span class="line"></span>
<span class="line"><span class="method">GET</span> <span class="url">http://localhost:8000/redirect-relative</span></span>
<span class="line section-header">[Options]</span>
<span class="line"><span class="string">location</span><span>:</span> <span class="boolean">true</span></span>
</span><span class="response"><span class="line"></span>
<span class="line"><span class="version">HTTP/1.0</span> <span class="number">200</span></span>
<span class="line section-header">[Asserts]</span>
<span class="line"><span class="query-type">url</span> <span class="predicate-type">==</span> <span class="string">"http://localhost:8000/redirected"</span></span>
<span class="raw"><span class="line">```Redirected```</span></span>
</span></span><span class="line"></span>
<span class="line"></span>
<span class="line"></span>
<span class="line"></span>
<span class="line"></span>
</code></pre>
</span></span></code></pre>

View File

@ -1,5 +1,7 @@
GET http://localhost:8000/redirected
HTTP/1.0 200
[Asserts]
url == "http://localhost:8000/redirected"
```Redirected```
@ -8,12 +10,16 @@ HTTP/1.0 200
GET http://localhost:8000/redirect-absolute
HTTP/1.0 302
Location: http://localhost:8000/redirected
[Asserts]
url == "http://localhost:8000/redirect-absolute"
GET http://localhost:8000/redirect-absolute
[Options]
location: true
HTTP/1.0 200
[Asserts]
url == "http://localhost:8000/redirected"
```Redirected```
@ -22,15 +28,14 @@ HTTP/1.0 200
GET http://localhost:8000/redirect-relative
HTTP/1.0 302
Location: /redirected
[Asserts]
url == "http://localhost:8000/redirect-relative"
GET http://localhost:8000/redirect-relative
[Options]
location: true
HTTP/1.0 200
[Asserts]
url == "http://localhost:8000/redirected"
```Redirected```

View File

@ -1 +1 @@
{"entries":[{"request":{"method":"GET","url":"http://localhost:8000/redirected"},"response":{"version":"HTTP/1.0","status":200,"body":{"type":"raw-string","value":"Redirected"}}},{"request":{"method":"GET","url":"http://localhost:8000/redirect-absolute"},"response":{"version":"HTTP/1.0","status":302,"headers":[{"name":"Location","value":"http://localhost:8000/redirected"}]}},{"request":{"method":"GET","url":"http://localhost:8000/redirect-absolute"},"response":{"version":"HTTP/1.0","status":200,"body":{"type":"raw-string","value":"Redirected"}}},{"request":{"method":"GET","url":"http://localhost:8000/redirect-relative"},"response":{"version":"HTTP/1.0","status":302,"headers":[{"name":"Location","value":"/redirected"}]}},{"request":{"method":"GET","url":"http://localhost:8000/redirect-relative"},"response":{"version":"HTTP/1.0","status":200,"body":{"type":"raw-string","value":"Redirected"}}}]}
{"entries":[{"request":{"method":"GET","url":"http://localhost:8000/redirected"},"response":{"version":"HTTP/1.0","status":200,"asserts":[{"query":{"type":"url"},"predicate":{"type":"equal","value":"http://localhost:8000/redirected"}}],"body":{"type":"raw-string","value":"Redirected"}}},{"request":{"method":"GET","url":"http://localhost:8000/redirect-absolute"},"response":{"version":"HTTP/1.0","status":302,"headers":[{"name":"Location","value":"http://localhost:8000/redirected"}],"asserts":[{"query":{"type":"url"},"predicate":{"type":"equal","value":"http://localhost:8000/redirect-absolute"}}]}},{"request":{"method":"GET","url":"http://localhost:8000/redirect-absolute"},"response":{"version":"HTTP/1.0","status":200,"asserts":[{"query":{"type":"url"},"predicate":{"type":"equal","value":"http://localhost:8000/redirected"}}],"body":{"type":"raw-string","value":"Redirected"}}},{"request":{"method":"GET","url":"http://localhost:8000/redirect-relative"},"response":{"version":"HTTP/1.0","status":302,"headers":[{"name":"Location","value":"/redirected"}],"asserts":[{"query":{"type":"url"},"predicate":{"type":"equal","value":"http://localhost:8000/redirect-relative"}}]}},{"request":{"method":"GET","url":"http://localhost:8000/redirect-relative"},"response":{"version":"HTTP/1.0","status":200,"asserts":[{"query":{"type":"url"},"predicate":{"type":"equal","value":"http://localhost:8000/redirected"}}],"body":{"type":"raw-string","value":"Redirected"}}}]}

View File

@ -58,6 +58,7 @@ pub fn eval_query_value(
) -> QueryResult {
match query.value.clone() {
QueryValue::Status {} => Ok(Some(Value::Integer(i64::from(http_response.status)))),
QueryValue::Url {} => Ok(Some(Value::String(http_response.url.clone()))),
QueryValue::Header { name, .. } => {
let header_name = eval_template(&name, variables)?;
let values = http_response.get_header_values(&header_name);

View File

@ -308,6 +308,7 @@ pub struct Query {
#[allow(clippy::large_enum_variant)]
pub enum QueryValue {
Status {},
Url {},
Header {
space0: Whitespace,
name: Template,

View File

@ -510,6 +510,9 @@ impl Htmlable for QueryValue {
QueryValue::Status {} => {
buffer.push_str("<span class=\"query-type\">status</span>");
}
QueryValue::Url {} => {
buffer.push_str("<span class=\"query-type\">url</span>");
}
QueryValue::Header { space0, name } => {
buffer.push_str("<span class=\"query-type\">header</span>");
buffer.push_str(space0.to_html().as_str());

View File

@ -60,6 +60,7 @@ fn query_value(reader: &mut Reader) -> ParseResult<'static, QueryValue> {
choice(
vec![
status_query,
url_query,
header_query,
cookie_query,
body_query,
@ -81,6 +82,11 @@ fn status_query(reader: &mut Reader) -> ParseResult<'static, QueryValue> {
Ok(QueryValue::Status {})
}
fn url_query(reader: &mut Reader) -> ParseResult<'static, QueryValue> {
try_literal("url", reader)?;
Ok(QueryValue::Url {})
}
fn header_query(reader: &mut Reader) -> ParseResult<'static, QueryValue> {
try_literal("header", reader)?;
let space0 = one_or_more_spaces(reader)?;

View File

@ -281,6 +281,9 @@ fn query_value_attributes(query_value: &QueryValue) -> Vec<(String, JValue)> {
QueryValue::Status {} => {
attributes.push(("type".to_string(), JValue::String("status".to_string())));
}
QueryValue::Url {} => {
attributes.push(("type".to_string(), JValue::String("url".to_string())));
}
QueryValue::Body {} => {
attributes.push(("type".to_string(), JValue::String("body".to_string())));
}

View File

@ -410,6 +410,7 @@ impl Tokenizable for QueryValue {
let mut tokens: Vec<Token> = vec![];
match self.clone() {
QueryValue::Status {} => tokens.push(Token::QueryType(String::from("status"))),
QueryValue::Url {} => tokens.push(Token::QueryType(String::from("url"))),
QueryValue::Header { space0, name } => {
tokens.push(Token::QueryType(String::from("header")));
tokens.append(&mut space0.tokenize());

View File

@ -271,6 +271,7 @@ impl Lintable<QueryValue> for QueryValue {
fn lint(&self) -> QueryValue {
match self {
QueryValue::Status {} => QueryValue::Status {},
QueryValue::Url {} => QueryValue::Url {},
QueryValue::Header { name, .. } => QueryValue::Header {
name: name.clone(),
space0: one_whitespace(),