Documentation
¶
Overview ¶
Example ¶
package main
import (
"fmt"
"net/http"
"github.com/linkdata/httpproxy"
)
func main() {
mux := http.NewServeMux()
mux.HandleFunc("/{$}", func(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "This is a web proxy server.")
})
// the httpproxy.Server will handle CONNECT and absolute URL requests,
// and all others will be forwarded to the http.Handler we set.
go http.ListenAndServe(":8080", &httpproxy.Server{Handler: mux})
}
Index ¶
- Variables
- func DefaultMakeRoundTripper(cd ContextDialer) http.RoundTripper
- func GetBasicAuth(hdr http.Header) (username, password string, err error)
- func RemoveRequestHeaders(r *http.Request)
- func SetBasicAuth(hdr http.Header, username, password string)
- type ContextDialer
- type CredentialsValidator
- type DialerSelector
- type Logger
- type RoundTripperMaker
- type Server
- type StaticCredentials
- type WriterFlusher
Examples ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ErrBodyNotReadWriter = errors.New("response body not an io.ReadWriter")
View Source
var ErrHijackingNotSupported = errors.New("http.ResponseWriter does not support http.Hijacker")
View Source
var MaxCachedRoundTrippers = 100
Functions ¶
func DefaultMakeRoundTripper ¶
func DefaultMakeRoundTripper(cd ContextDialer) http.RoundTripper
DefaultMakeRoundTripper clones http.DefaultTransport, sets it's DialContext member and returns it.
func RemoveRequestHeaders ¶
RemoveRequestHeaders removes request headers which should not propagate to the next hop.
func SetBasicAuth ¶
Types ¶
type ContextDialer ¶
type ContextDialer interface {
DialContext(ctx context.Context, network, address string) (conn net.Conn, err error)
}
var DefaultContextDialer ContextDialer = &net.Dialer{}
type CredentialsValidator ¶
type CredentialsValidator interface {
ValidateCredentials(username, password, address string) bool
}
CredentialsValidator is used to support user/pass authentication optional network address filtering.
type DialerSelector ¶
type DialerSelector interface {
// SelectDialer returns the ContextDialer to use.
//
// If username is the empty string no authorization has taken place (anonymous usage).
// If you return the error httpproxy.ErrUnauthorized then httpproxy will generate
// the HTTP status code 401 Unauthorized.
SelectDialer(username, network, address string) (cd ContextDialer, err error)
}
A DialerSelector returns the ContextDialer to use.
type Logger ¶
type Logger interface {
Debug(msg string, keyValuePairs ...any)
Info(msg string, keyValuePairs ...any)
Warn(msg string, keyValuePairs ...any)
Error(msg string, keyValuePairs ...any)
}
Logger matches the log/slog.Logger interface.
type RoundTripperMaker ¶
type RoundTripperMaker interface {
MakeRoundTripper(cd ContextDialer) (rt http.RoundTripper)
}
type Server ¶
type Server struct {
Logger Logger // optional logger to use
Handler http.Handler // optional handler for requests that aren't proxy requests
DialerSelector DialerSelector // optional handler to select ContextDialer per proxy request, otherwise uses DefaultContextDialer
CredentialsValidator CredentialsValidator // optional credentials validator
RoundTripperMaker RoundTripperMaker // optional RoundTripperMaker, defaults to DefaultMakeRoundTripper
// contains filtered or unexported fields
}
type StaticCredentials ¶
StaticCredentials enables using a map directly as a credential store
func (StaticCredentials) ValidateCredentials ¶
func (s StaticCredentials) ValidateCredentials(username, password, _ string) bool
Click to show internal directories.
Click to hide internal directories.