github.com/searKing/golang/go@v1.2.117/net/http/httphost/example_test.go (about) 1 // Copyright 2022 The searKing Author. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 package httphost_test 6 7 import ( 8 "log" 9 "net/http" 10 11 http_ "github.com/searKing/golang/go/net/http" 12 "github.com/searKing/golang/go/net/http/httphost" 13 _ "github.com/searKing/golang/go/net/resolver/passthrough" 14 ) 15 16 func Example() { 17 req, _ := http.NewRequest("GET", "http://example.com", nil) 18 proxy := &httphost.Host{ 19 HostTarget: "127.0.0.1", 20 } 21 req = req.WithContext(httphost.WithHost(req.Context(), proxy)) 22 23 err := http_.HostFuncFromContext(req) 24 if err != nil { 25 log.Fatal(err) 26 } 27 28 _, err = http.DefaultClient.Do(req) 29 if err != nil { 30 log.Fatal(err) 31 } 32 }