httpproxy

package
v1.2.116 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 7, 2024 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Example
package main

import (
	"log"
	"net/http"

	http_ "github.com/searKing/golang/go/net/http"
	"github.com/searKing/golang/go/net/http/httpproxy"

	_ "github.com/searKing/golang/go/net/resolver/passthrough"
)

func main() {
	req, _ := http.NewRequest("GET", "http://example.com", nil)
	proxy := &httpproxy.Proxy{
		ProxyUrl:    "socks5://proxy.example.com:8080",
		ProxyTarget: "127.0.0.1",
	}
	req = req.WithContext(httpproxy.WithProxy(req.Context(), proxy))

	_, err := http_.DefaultTransportWithDynamicProxy.RoundTrip(req)
	if err != nil {
		log.Fatal(err)
	}
}
Output:

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func ParseProxyUrl

func ParseProxyUrl(proxy string) (*url.URL, error)

func WithProxy

func WithProxy(ctx context.Context, proxy *Proxy) context.Context

WithProxy returns a new context based on the provided parent ctx. HTTP client requests made with the returned context will use the provided proxy hooks

Types

type Proxy

type Proxy struct {
	// ProxyUrl is proxy's url, like socks5://127.0.0.1:8080
	ProxyUrl string
	// ProxyTarget is as like gRPC Naming for proxy service discovery, with Host in ProxyUrl replaced if not empty.
	ProxyTarget string

	// ProxyAddrResolved is the proxy's addr resolved and picked from resolver.
	ProxyAddrResolved resolver.Address
}

Proxy specifies ProxyUrl and ProxyTarget to return a dynamic proxy.

func ContextProxy

func ContextProxy(ctx context.Context) *Proxy

ContextProxy returns the Proxy associated with the provided context. If none, it returns nil.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL