mirror of
https://github.com/nushell/nushell.git
synced 2025-06-11 20:46:48 +02:00
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:
parent
02d63705cc
commit
dbb30cc9e0
@ -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
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user