Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CHORE: Add proxy-insecure option similar to curl #9

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
module github.com/thekvs/microproxy

go 1.14
go 1.22

require (
github.com/BurntSushi/toml v0.3.1
github.com/elazarl/goproxy v0.0.0-20200809112317-0581fc3aee2d
github.com/BurntSushi/toml v1.3.2
github.com/elazarl/goproxy v0.0.0-20231117061959-7cc037d33fb5
)
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/elazarl/goproxy v0.0.0-20200809112317-0581fc3aee2d h1:rtM8HsT3NG37YPjz8sYSbUSdElP9lUsQENYzJDZDUBE=
github.com/elazarl/goproxy v0.0.0-20200809112317-0581fc3aee2d/go.mod h1:Ro8st/ElPeALwNFlcTpWmkr6IoMFfkjXAvTHpevnDsM=
github.com/BurntSushi/toml v1.3.2 h1:o7IhLm0Msx3BaB+n3Ag7L8EVlByGnpq14C4YWiu/gL8=
github.com/BurntSushi/toml v1.3.2/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ=
github.com/elazarl/goproxy v0.0.0-20231117061959-7cc037d33fb5 h1:m62nsMU279qRD9PQSWD1l66kmkXzuYcnVJqL4XLeV2M=
github.com/elazarl/goproxy v0.0.0-20231117061959-7cc037d33fb5/go.mod h1:Ro8st/ElPeALwNFlcTpWmkr6IoMFfkjXAvTHpevnDsM=
github.com/elazarl/goproxy/ext v0.0.0-20190711103511-473e67f1d7d2 h1:dWB6v3RcOy03t/bUadywsbyrQwCqZeNIEX6M1OtSZOM=
github.com/elazarl/goproxy/ext v0.0.0-20190711103511-473e67f1d7d2/go.mod h1:gNh8nYJoAm43RfaxurUnxr+N1PwuFV3ZMl/efxlIlY8=
github.com/rogpeppe/go-charset v0.0.0-20180617210344-2471d30d28b4/go.mod h1:qgYeAmZ5ZIpBWTGllZSQnw97Dj+woV0toclVaRGI8pc=
12 changes: 11 additions & 1 deletion microproxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"context"
"crypto/tls"
"encoding/base64"
"flag"
"fmt"
Expand Down Expand Up @@ -430,7 +431,11 @@ func setForwardProxy(conf *Configuration, proxy *goproxy.ProxyHttpServer) {
connectHandler := func(req *http.Request) {
req.Header.Del(ProxyAuthorizatonHeader)
if len(u.User.Username()) > 0 {
req.Header.Set(ProxyAuthorizatonHeader, "Basic "+base64.StdEncoding.EncodeToString([]byte(u.User.String())))
creds, err := url.QueryUnescape(u.User.String())
if err != nil {
proxy.Logger.Printf("can't decode the user credentials: %v", err)
}
req.Header.Set(ProxyAuthorizatonHeader, "Basic "+base64.StdEncoding.EncodeToString([]byte(creds)))
}
}
proxy.ConnectDial = proxy.NewConnectDialToProxyWithHandler(conf.ForwardProxyURL, connectHandler)
Expand All @@ -441,6 +446,7 @@ func setForwardProxy(conf *Configuration, proxy *goproxy.ProxyHttpServer) {

func main() {
configFile := flag.String("config", "microproxy.toml", "proxy configuration file")
proxyInsecure := flag.Bool("i", false, "allow insecure forward proxy connections")
testConfigOnly := flag.Bool("t", false, "only test configuration file")
verboseMode := flag.Bool("v", false, "enable verbose debug mode")

Expand Down Expand Up @@ -471,6 +477,10 @@ func main() {
// has to be placed last in the source code.
setAuthenticationHandler(conf, proxy, logger)

proxy.Tr.TLSClientConfig = &tls.Config{
InsecureSkipVerify: *proxyInsecure,
}

proxy.Logger.Printf("starting proxy\n")

log.Fatal(http.ListenAndServe(conf.Listen, proxy))
Expand Down
7 changes: 2 additions & 5 deletions vendor/github.com/BurntSushi/toml/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 0 additions & 15 deletions vendor/github.com/BurntSushi/toml/.travis.yml

This file was deleted.

3 changes: 0 additions & 3 deletions vendor/github.com/BurntSushi/toml/COMPATIBLE

This file was deleted.

19 changes: 0 additions & 19 deletions vendor/github.com/BurntSushi/toml/Makefile

This file was deleted.

230 changes: 66 additions & 164 deletions vendor/github.com/BurntSushi/toml/README.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading