Changeset 134 in code


Ignore:
Timestamp:
Feb 27, 2021, 6:29:10 AM (4 years ago)
Author:
aurelien
Message:

[enh] implement HTTP proxy over environment variables
[enh] implement custom HTP proxy over command line (proxy auth supported)
[enh] allow for IPv4 only connectivity
[enh] improve help message for each option
[enh] log connection method on startup
[fix] ensure all connectivity flags (-proxyenv,-proxy, -socks5, -ipv6) are mutually exclusive

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/morty.go

    r132 r134  
    3838)
    3939
    40 const VERSION = "v0.2.0"
     40const VERSION = "v0.2.1"
    4141
    4242const MAX_REDIRECT_COUNT = 5
     
    10571057        cfg.ListenAddress = *flag.String("listen", cfg.ListenAddress, "Listen address")
    10581058        cfg.Key = *flag.String("key", cfg.Key, "HMAC url validation key (base64 encoded) - leave blank to disable validation")
    1059         cfg.IPV6 = *flag.Bool("ipv6", cfg.IPV6, "Allow IPv6 HTTP requests")
    10601059        cfg.Debug = *flag.Bool("debug", cfg.Debug, "Debug mode")
    10611060        cfg.RequestTimeout = *flag.Uint("timeout", cfg.RequestTimeout, "Request timeout")
    10621061        cfg.FollowRedirect = *flag.Bool("followredirect", cfg.FollowRedirect, "Follow HTTP GET redirect")
     1062        proxyenv := flag.Bool("proxyenv", false, "Use a HTTP proxy as set in the environment (HTTP_PROXY, HTTPS_PROXY and NO_PROXY). Overrides -proxy, -socks5, -ipv6.")
     1063        proxy := flag.String("proxy", "", "Use the specified HTTP proxy (ie: '[user:pass@]hostname:port'). Overrides -socks5, -ipv6.")
     1064        socks5 := flag.String("socks5", "", "Use a SOCKS5 proxy (ie: 'hostname:port'). Overrides -ipv6.")
     1065        cfg.IPV6 = *flag.Bool("ipv6", cfg.IPV6, "Use IPv6 and IPv4 to send HTTP requests.")
    10631066        version := flag.Bool("version", false, "Show version")
    1064         socks5 := flag.String("socks5", "", "SOCKS5 proxy")
    10651067        flag.Parse()
    10661068
     
    10701072        }
    10711073
    1072         if *socks5 != "" {
    1073                 // this disables CLIENT.DialDualStack
     1074        if *proxyenv && os.Getenv("HTTP_PROXY") == "" && os.Getenv("HTTPS_PROXY") == "" {
     1075                log.Fatal("Error -proxyenv is used but no environment variables named 'HTTP_PROXY' and/or 'HTTPS_PROXY' could be found.")
     1076                os.Exit(1)
     1077        }
     1078
     1079        if *proxyenv && (os.Getenv("HTTP_PROXY") != "" || os.Getenv("HTTPS_PROXY") != "") {
     1080                CLIENT.Dial = fasthttpproxy.FasthttpProxyHTTPDialer()
     1081                log.Println("Using environment defined proxy(ies).")
     1082        } else if *proxy != "" {
     1083                CLIENT.Dial = fasthttpproxy.FasthttpHTTPDialer(*proxy)
     1084                log.Println("Using custom HTTP proxy.")
     1085        } else if *socks5 != "" {
    10741086                CLIENT.Dial = fasthttpproxy.FasthttpSocksDialer(*socks5)
    1075         }
    1076         if cfg.IPV6 {
     1087                log.Println("Using Socks5 proxy.")
     1088        } else if cfg.IPV6 {
    10771089                CLIENT.Dial = fasthttp.DialDualStack
     1090                log.Println("Using dual stack (IPv4/IPv6) direct connections.")
     1091        } else {
     1092                CLIENT.Dial = fasthttp.Dial
     1093                log.Println("Using IPv4 only direct connections.")
    10781094        }
    10791095
Note: See TracChangeset for help on using the changeset viewer.