mirror of
https://github.com/Orange-OpenSource/hurl.git
synced 2024-11-22 15:42:20 +03:00
Fix HTTP HEAD
This commit is contained in:
parent
e85354f0eb
commit
6472866c22
1
integration/tests_ok/head.curl
Normal file
1
integration/tests_ok/head.curl
Normal file
@ -0,0 +1 @@
|
||||
curl 'http://localhost:8000/head' --head
|
9
integration/tests_ok/head.html
Normal file
9
integration/tests_ok/head.html
Normal file
@ -0,0 +1,9 @@
|
||||
<pre><code class="language-hurl"><span class="hurl-entry"><span class="request"><span class="line"><span class="method">HEAD</span> <span class="url">http://localhost:8000/head</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"><span class="string">Content-Type</span><span>:</span> <span class="string">text/html; charset=utf-8</span></span>
|
||||
<span class="line"><span class="string">Content-Length</span><span>:</span> <span class="string">10</span></span>
|
||||
<span class="line"><span class="string">Server</span><span>:</span> <span class="string">Flask Server</span></span>
|
||||
<span class="line section-header">[Asserts]</span>
|
||||
<span class="line"><span class="query-type">bytes</span> <span class="subquery-type">count</span> <span class="predicate-type">==</span> <span class="number">0</span></span>
|
||||
</span></span><span class="line"></span>
|
||||
</code></pre>
|
8
integration/tests_ok/head.hurl
Normal file
8
integration/tests_ok/head.hurl
Normal file
@ -0,0 +1,8 @@
|
||||
HEAD http://localhost:8000/head
|
||||
HTTP/1.0 200
|
||||
Content-Type: text/html; charset=utf-8
|
||||
Content-Length: 10
|
||||
Server: Flask Server
|
||||
[Asserts]
|
||||
bytes count == 0
|
||||
|
1
integration/tests_ok/head.json
Normal file
1
integration/tests_ok/head.json
Normal file
@ -0,0 +1 @@
|
||||
{"entries":[{"request":{"method":"HEAD","url":"http://localhost:8000/head"},"response":{"version":"HTTP/1.0","status":200,"headers":[{"name":"Content-Type","value":"text/html; charset=utf-8"},{"name":"Content-Length","value":"10"},{"name":"Server","value":"Flask Server"}],"asserts":[{"query":{"type":"bytes","subquery":{"type":"count"}},"predicate":{"type":"equal","value":0}}]}}]}
|
6
integration/tests_ok/head.py
Normal file
6
integration/tests_ok/head.py
Normal file
@ -0,0 +1,6 @@
|
||||
from app import app
|
||||
|
||||
|
||||
@app.route("/head")
|
||||
def head():
|
||||
return "Hello Head"
|
@ -182,6 +182,10 @@ impl Client {
|
||||
// of key-value.
|
||||
let mut request_body = Vec::<u8>::new();
|
||||
let mut response_body = Vec::<u8>::new();
|
||||
|
||||
if *method == Method::Head {
|
||||
self.handle.nobody(true).unwrap();
|
||||
}
|
||||
{
|
||||
let mut transfer = self.handle.transfer();
|
||||
if !request_spec_body.is_empty() {
|
||||
@ -189,6 +193,7 @@ impl Client {
|
||||
.read_function(|buf| Ok(request_spec_body.read(buf).unwrap_or(0)))
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
transfer
|
||||
.debug_function(|info_type, data| match info_type {
|
||||
// Return all request headers (not one by one)
|
||||
|
@ -118,7 +118,7 @@ impl Method {
|
||||
vec![]
|
||||
}
|
||||
}
|
||||
Method::Head => vec!["-X".to_string(), "HEAD".to_string()],
|
||||
Method::Head => vec!["--head".to_string()],
|
||||
Method::Post => {
|
||||
if data {
|
||||
vec![]
|
||||
|
@ -1132,6 +1132,39 @@ fn test_insecure() {
|
||||
assert_eq!(response.status, 200);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_head() {
|
||||
let options = ClientOptions {
|
||||
..Default::default()
|
||||
};
|
||||
let context_dir = ContextDir::default();
|
||||
let mut client = Client::new(None);
|
||||
let logger = Logger::new(false, false, "", "");
|
||||
let request_spec = RequestSpec {
|
||||
method: Method::Head,
|
||||
url: "http://localhost:8000/head".to_string(),
|
||||
headers: vec![],
|
||||
querystring: vec![],
|
||||
form: vec![],
|
||||
multipart: vec![],
|
||||
cookies: vec![],
|
||||
body: Body::Binary(vec![]),
|
||||
content_type: None,
|
||||
};
|
||||
assert_eq!(
|
||||
client.curl_command_line(&request_spec, &context_dir, &options),
|
||||
"curl 'http://localhost:8000/head' --head".to_string()
|
||||
);
|
||||
|
||||
let (request, response) = client.execute(&request_spec, &options, &logger).unwrap();
|
||||
assert_eq!(request.url, "http://localhost:8000/head");
|
||||
assert_eq!(response.status, 200);
|
||||
assert!(response.headers.contains(&Header {
|
||||
name: "Content-Length".to_string(),
|
||||
value: "10".to_string(),
|
||||
}));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_version() {
|
||||
// This test if only informative for the time-being
|
||||
|
Loading…
Reference in New Issue
Block a user