Skip to content

Commit

Permalink
Assume HTTP when no scheme is set in a request
Browse files Browse the repository at this point in the history
If a request lacks a scheme such as http:// or https:// when the
request is performed (for example, the URL is set to
example.com/api/foobar, not https://example.com/api/foobar), http://
will be prepended to the request URL.
  • Loading branch information
danirod committed Jan 26, 2025
1 parent 1c4144a commit b3c4c01
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/widgets/endpoint_pane.rs
Original file line number Diff line number Diff line change
Expand Up @@ -398,8 +398,21 @@ mod imp {
})
}

/// Add http:// to the beginning of the typed URL if the protocol has not been specified.
fn assert_protocol(&self) {
let url = self.request_url.text().to_string();
if let Ok(url_object) = Url::parse(&url) {
if !url_object.scheme().is_empty() {
return;
}
}
let protocoled_url = format!("http://{}", url);
self.request_url.set_text(&protocoled_url);
}

/// Executes an HTTP request based on the current contents of the pane.
pub(super) async fn perform_request(&self) -> Result<(), CarteroError> {
self.assert_protocol();
let request = self.extract_endpoint()?;
let request = BoundRequest::try_from(request)?;
let request_obj = isahc::Request::try_from(request)?;
Expand Down

0 comments on commit b3c4c01

Please sign in to comment.