first pass at supporting a default base URL

this allows remote images to be specified as relative URLs, relative to
the `DefaultBaseURL` field.  Fixes #15.
This commit is contained in:
Will Norris 2015-02-19 21:34:22 -08:00
parent dbac2f8063
commit ad54d71881
5 changed files with 35 additions and 3 deletions

View file

@ -199,7 +199,7 @@ type Request struct {
// http://localhost/100x200,r90/http://example.com/image.jpg?foo=bar
// http://localhost//http://example.com/image.jpg
// http://localhost/http://example.com/image.jpg
func NewRequest(r *http.Request) (*Request, error) {
func NewRequest(r *http.Request, baseURL *url.URL) (*Request, error) {
var err error
req := new(Request)
@ -220,6 +220,10 @@ func NewRequest(r *http.Request) (*Request, error) {
req.Options = ParseOptions(parts[0])
}
if baseURL != nil {
req.URL = baseURL.ResolveReference(req.URL)
}
if !req.URL.IsAbs() {
return nil, URLError{"must provide absolute remote URL", r.URL}
}