Standard library / net/http

http.ProxyURL()

Return a proxy-selection callback that returns the supplied URL. This example only selects a proxy; it does not connect to one. Expected stdout: 'proxy.invalid:8080\n'.

Formal Syntax & Structure

go syntaxgo
func ProxyURL(fixedURL *url.URL) func(*Request) (*url.URL, error)

Parameters & Attributes

NameTypeDescription
fixedURL*url.URLProxy URL to return for requests.

Return Value

func(*Request) (*url.URL, error)

Operation result; check errors and validity indicators when returned.

Working Example

Example Snippetgo
package main
import (  "fmt"  "net/http"  "net/url")
func main() {  u := must(url.Parse("http://proxy.invalid:8080"))  f := http.ProxyURL(u)  q := must(http.NewRequest("GET", "http://example.invalid", nil))  fmt.Println(must(f(q)).Host)}
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