Remove default base URL of http://localhost/ (#108)
This doesn't change the API at all, since it delays any errors until do_call.
Since there was already an `Into<Response> for Error`, and do_call already
had a `.unwrap_or_else(|e| e.into())`, nothing in do_call needed to change.
The only visible effect of this is that code that was previously relying on
`get("/path")` to fetch something from localhost will now get an error. I think
most of those cases would probably actually be accidents, possibly caused
by typos, e.g. `get("example.com/path")` (forgetting the https: prefix).
Fixes #105
This commit is contained in:
@@ -2,7 +2,6 @@ use std::io::Read;
|
|||||||
use std::sync::{Arc, Mutex};
|
use std::sync::{Arc, Mutex};
|
||||||
use std::time;
|
use std::time;
|
||||||
|
|
||||||
use lazy_static::lazy_static;
|
|
||||||
use qstring::QString;
|
use qstring::QString;
|
||||||
use url::{form_urlencoded, Url};
|
use url::{form_urlencoded, Url};
|
||||||
|
|
||||||
@@ -20,10 +19,6 @@ use crate::Response;
|
|||||||
#[cfg(feature = "json")]
|
#[cfg(feature = "json")]
|
||||||
use super::SerdeValue;
|
use super::SerdeValue;
|
||||||
|
|
||||||
lazy_static! {
|
|
||||||
static ref URL_BASE: Url = Url::parse("http://localhost/").expect("Failed to parse URL_BASE");
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Request instances are builders that creates a request.
|
/// Request instances are builders that creates a request.
|
||||||
///
|
///
|
||||||
/// ```
|
/// ```
|
||||||
@@ -523,7 +518,7 @@ impl Request {
|
|||||||
/// .build();
|
/// .build();
|
||||||
/// assert_eq!(req1.get_host().unwrap(), "cool.server");
|
/// assert_eq!(req1.get_host().unwrap(), "cool.server");
|
||||||
///
|
///
|
||||||
/// let req2 = ureq::post("/some/path")
|
/// let req2 = ureq::post("http://localhost/some/path")
|
||||||
/// .build();
|
/// .build();
|
||||||
/// assert_eq!(req2.get_host().unwrap(), "localhost");
|
/// assert_eq!(req2.get_host().unwrap(), "localhost");
|
||||||
/// ```
|
/// ```
|
||||||
@@ -571,9 +566,7 @@ impl Request {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn to_url(&self) -> Result<Url, Error> {
|
fn to_url(&self) -> Result<Url, Error> {
|
||||||
URL_BASE
|
Url::parse(&self.url).map_err(|e| Error::BadUrl(format!("{}", e)))
|
||||||
.join(&self.url)
|
|
||||||
.map_err(|e| Error::BadUrl(format!("{}", e)))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Set the proxy server to use for the connection.
|
/// Set the proxy server to use for the connection.
|
||||||
|
|||||||
@@ -122,7 +122,7 @@ fn escape_path() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn request_debug() {
|
fn request_debug() {
|
||||||
let req = get("/my/page")
|
let req = get("http://localhost/my/page")
|
||||||
.set("Authorization", "abcdef")
|
.set("Authorization", "abcdef")
|
||||||
.set("Content-Length", "1234")
|
.set("Content-Length", "1234")
|
||||||
.set("Content-Type", "application/json")
|
.set("Content-Type", "application/json")
|
||||||
@@ -136,7 +136,7 @@ fn request_debug() {
|
|||||||
Content-Length: 1234, Content-Type: application/json])"
|
Content-Length: 1234, Content-Type: application/json])"
|
||||||
);
|
);
|
||||||
|
|
||||||
let req = get("/my/page?q=z")
|
let req = get("http://localhost/my/page?q=z")
|
||||||
.query("foo", "bar baz")
|
.query("foo", "bar baz")
|
||||||
.set("Authorization", "abcdef")
|
.set("Authorization", "abcdef")
|
||||||
.build();
|
.build();
|
||||||
|
|||||||
Reference in New Issue
Block a user