mirror of
https://github.com/willnorris/imageproxy.git
synced 2026-06-28 06:19:39 +02:00
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:
parent
dbac2f8063
commit
ad54d71881
5 changed files with 35 additions and 3 deletions
6
data.go
6
data.go
|
|
@ -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}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue