Add --http1.1 option

This commit is contained in:
jcamiel 2023-10-03 13:41:58 +02:00
parent 17ec6c8b1a
commit 411f0ed8f5
No known key found for this signature in database
GPG Key ID: 07FF11CFD55356CC
19 changed files with 35 additions and 7 deletions

View File

@ -1,3 +0,0 @@
#!/bin/bash
set -Eeuo pipefail
hurl --http1.0 tests_ok/http_version.hurl

View File

@ -1,3 +1,3 @@
Set-StrictMode -Version latest
$ErrorActionPreference = 'Stop'
hurl --http1.0 tests_ok/http_version.hurl
hurl --http1.0 tests_ok/http_version_10.hurl

View File

@ -0,0 +1,3 @@
#!/bin/bash
set -Eeuo pipefail
hurl --http1.0 tests_ok/http_version_10.hurl

View File

@ -0,0 +1 @@
curl --http1.1 'http://localhost:8000/http_version/11'

View File

@ -0,0 +1,3 @@
<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/http_version/11</span></span>
</span><span class="response"><span class="line"><span class="version">HTTP</span> <span class="number">200</span></span>
</span></span></code></pre>

View File

@ -0,0 +1,2 @@
GET http://localhost:8000/http_version/11
HTTP 200

View File

@ -0,0 +1 @@
{"entries":[{"request":{"method":"GET","url":"http://localhost:8000/http_version/11"},"response":{"status":200}}]}

View File

@ -0,0 +1 @@
HTTP/1.1

View File

@ -0,0 +1,3 @@
Set-StrictMode -Version latest
$ErrorActionPreference = 'Stop'
hurl --http1.1 tests_ok/http_version_11.hurl

View File

@ -0,0 +1,3 @@
#!/bin/bash
set -Eeuo pipefail
hurl --http1.1 tests_ok/http_version_11.hurl

View File

@ -169,6 +169,13 @@ pub fn http10() -> clap::Arg {
.action(ArgAction::SetTrue)
}
pub fn http11() -> clap::Arg {
clap::Arg::new("http11")
.long("http1.1")
.help("Tells curl to use HTTP version 1.1")
.action(ArgAction::SetTrue)
}
pub fn include() -> clap::Arg {
clap::Arg::new("include")
.short('i')

View File

@ -170,7 +170,9 @@ pub fn html_dir(arg_matches: &ArgMatches) -> Result<Option<PathBuf>, OptionsErro
}
pub fn http_version(arg_matches: &ArgMatches) -> Option<HttpVersion> {
if has_flag(arg_matches, "http10") {
if has_flag(arg_matches, "http11") {
Some(HttpVersion::V11)
} else if has_flag(arg_matches, "http10") {
Some(HttpVersion::V10)
} else {
None

View File

@ -106,12 +106,14 @@ pub enum ErrorFormat {
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub enum HttpVersion {
V10,
V11,
}
impl From<HttpVersion> for http::HttpVersion {
fn from(value: HttpVersion) -> Self {
match value {
HttpVersion::V10 => http::HttpVersion::Http10,
HttpVersion::V11 => http::HttpVersion::Http11,
}
}
}
@ -159,6 +161,7 @@ pub fn parse() -> Result<Options, OptionsError> {
.arg(commands::follow_location())
.arg(commands::glob())
.arg(commands::http10())
.arg(commands::http11())
.arg(commands::ignore_asserts())
.arg(commands::include())
.arg(commands::input_files())

View File

@ -120,8 +120,10 @@ impl ClientOptions {
if self.insecure {
arguments.push("--insecure".to_string());
}
if self.http_version == Some(HttpVersion::Http10) {
arguments.push("--http1.0".to_string());
match self.http_version {
Some(HttpVersion::Http10) => arguments.push("--http1.0".to_string()),
Some(HttpVersion::Http11) => arguments.push("--http1.1".to_string()),
_ => {}
}
if self.follow_location {
arguments.push("--location".to_string());