diff options
| author | Adnan Maolood <[email protected]> | 2020-10-27 13:27:52 -0400 |
|---|---|---|
| committer | Adnan Maolood <[email protected]> | 2020-10-27 13:27:52 -0400 |
| commit | 8ab40648418c1770985b2a159343442453bd40c4 (patch) | |
| tree | 5fa00e55cc5f2507daf2d5c7f2bf35e3dc49af68 /request.go | |
| parent | Remove (Text).HTML function (diff) | |
| download | go-gemini-8ab40648418c1770985b2a159343442453bd40c4.tar.xz go-gemini-8ab40648418c1770985b2a159343442453bd40c4.zip | |
Add NewRequestFromURL function
Diffstat (limited to 'request.go')
| -rw-r--r-- | request.go | 13 |
1 files changed, 9 insertions, 4 deletions
@@ -42,22 +42,27 @@ func hostname(host string) string { return hostname } -// NewRequest returns a new request. The host is inferred from the provided URL. +// NewRequest returns a new request. The host is inferred from the URL. func NewRequest(rawurl string) (*Request, error) { u, err := url.Parse(rawurl) if err != nil { return nil, err } + return NewRequestFromURL(u) +} +// NewRequestFromURL returns a new request for the given URL. +// The host is inferred from the URL. +func NewRequestFromURL(url *url.URL) (*Request, error) { // If there is no port, use the default port of 1965 - host := u.Host - if u.Port() == "" { + host := url.Host + if url.Port() == "" { host += ":1965" } return &Request{ Host: host, - URL: u, + URL: url, }, nil } |