-
Notifications
You must be signed in to change notification settings - Fork 168
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remove default host of localhost #105
Comments
This comes from that early ureq API was modelled on superagent, which is still my goto nodejs http client and somewhat of a hero for me in API design.
Is it? If we ask "what could the user possibly mean with this input?" Philosophically both ureq (and now hreq), were and are driven by a feeling that in the rust community, sometimes correctness and strict adherence to spec overrides usability concerns in API design. The http crate is better now, but the correctness of hyper, where the http crate started, often shows in the API the user is exposed to.
For example this method signature: impl Request {
fn header(&self, key: &str) -> Option<&str> { … }
} is no good if the overriding concern for the API is correctness. Not all correct header values can be represented as rust But how often do we really encounter such headers in the wild? I want ureq (and hreq) to be correct and on spec, I want to be able to handle such headers if I find them, but without forcing the user of the API to jump through hoops. Simple, rememberable and User first API (how I encapsulated these thoughts in a design goal). This is the bigger picture of the absence of In early ureq I did however lurch too far in the other direction, so in the same way I'm for reintroducing some |
Thanks for the additional background on the API design! I think we can probably find a middle path, where we keep the API simple and also filter out some error cases, by deferring all errors until |
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
Request::new can be called with something that's not a URL, e.g.
/path
, and it will automatically prependhttp://localhost/
. I think that's the wrong thing in most cases. We should instead make it an error to construct a Request with a string that doesn't parse as a URL.This will probably break a lot of doctests, but I think we should update the doctests to use real URLs. For now those can be
http://localhost/
; when #82 is fixed, those can behttp://example.com/
, with an override to pointexample.com
tolocalhost
so the tests run quickly and don't hit the network.The text was updated successfully, but these errors were encountered: