Standard library / net/http

http.Request.Referer()

Return the Referer header value; it is not trustworthy proof of origin. Expected stdout: 'https://example.invalid/\n'.

Formal Syntax & Structure

go syntaxgo
func (r *Request) Referer() string

Return Value

string

Operation result; check errors and validity indicators when returned.

Working Example

Example Snippetgo
package main
import (  "fmt"  "net/http")
func main() {  r := must(http.NewRequest("GET", "https://example.invalid/", nil))  r.Header.Set("Referer", "https://example.invalid/")  fmt.Println(r.Referer())}
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