feat: default http protocol when none used in http request (#15804)

https://github.com/nushell/nushell/issues/10957

Hello, this PR proposes a solution for some requested features mentioned
in https://github.com/nushell/nushell/issues/10957. I personally think
these are very simple changes that bring significant quality of life
improvements.
It gives the possibility to do `http get google.com` instead of `http
get http://google.com` and `http get :8080` instead of `http get
http://localhost:8080`.
I did not address the other part of the issue (data management) as those
are more controversial.
This commit is contained in:
Noah 2025-05-24 19:53:59 +02:00 committed by GitHub
parent 02d63705cc
commit dbb30cc9e0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -78,12 +78,22 @@ pub fn http_parse_url(
span: Span,
raw_url: Value,
) -> Result<(String, Url), ShellError> {
let requested_url = raw_url.coerce_into_string()?;
let mut requested_url = raw_url.coerce_into_string()?;
if requested_url.starts_with(':') {
requested_url = format!("http://localhost{}", requested_url);
} else if !requested_url.contains("://") {
requested_url = format!("http://{}", requested_url);
}
let url = match url::Url::parse(&requested_url) {
Ok(u) => u,
Err(_e) => {
return Err(ShellError::UnsupportedInput { msg: "Incomplete or incorrect URL. Expected a full URL, e.g., https://www.example.com"
.to_string(), input: format!("value: '{requested_url:?}'"), msg_span: call.head, input_span: span });
return Err(ShellError::UnsupportedInput {
msg: "Incomplete or incorrect URL. Expected a full URL, e.g., https://www.example.com".to_string(),
input: format!("value: '{requested_url:?}'"),
msg_span: call.head,
input_span: span
});
}
};