Standard library / net/http

http.Response.Location()

Return a parsed Location header, resolving relative URLs against the originating request when available. Expected stdout: 'https://example.invalid/next\n'.

Formal Syntax & Structure

go syntaxgo
func (r *Response) Location() (*url.URL, error)

Return Value

(*url.URL, error)

Operation result; check errors and validity indicators when returned.

Working Example

Example Snippetgo
package main
import (  "fmt"  "net/http")
func main() {  r := &http.Response{Header: http.Header{"Location": {"/next"}}, Request: must(http.NewRequest("GET", "https://example.invalid/", nil))}  fmt.Println(must(r.Location()))}
func must[T any](v T, e error) T {  if e != nil {    panic(e)  }  return v}func check(e error) {  if e != nil {    panic(e)  }}
Go Reference