1
0
mirror of https://github.com/oauth2-proxy/oauth2-proxy.git synced 2025-06-15 00:15:00 +02:00

Added scheme parsing to http-address param

Can now listen for HTTP clients on unix sockets (and any other Go-supported stream oriented network - see golang.org/pkg/net/#Listen).  Default behaviour is unchanged, any http-address without a scheme is given the default of tcp.

Amended the README so that the usage output is up to date.
This commit is contained in:
David Howden
2015-02-11 12:07:40 +11:00
parent 601ae6f4ec
commit 975c7173c2
2 changed files with 25 additions and 7 deletions

23
main.go
View File

@ -6,6 +6,7 @@ import (
"log"
"net"
"net/http"
"net/url"
"os"
"strings"
"time"
@ -24,7 +25,7 @@ func main() {
config := flagSet.String("config", "", "path to config file")
showVersion := flagSet.Bool("version", false, "print version string")
flagSet.String("http-address", "127.0.0.1:4180", "<addr>:<port> to listen on for HTTP clients")
flagSet.String("http-address", "127.0.0.1:4180", "[http://]<addr>:<port> or unix://<path> to listen on for HTTP clients")
flagSet.String("redirect-url", "", "the OAuth Redirect URL. ie: \"https://internalapp.yourcompany.com/oauth2/callback\"")
flagSet.Var(&upstreams, "upstream", "the http url(s) of the upstream endpoint. If multiple, routing is based on path")
flagSet.Bool("pass-basic-auth", true, "pass HTTP Basic Auth, X-Forwarded-User and X-Forwarded-Email information to upstream")
@ -88,11 +89,25 @@ func main() {
}
}
listener, err := net.Listen("tcp", opts.HttpAddress)
u, err := url.Parse(opts.HttpAddress)
if err != nil {
log.Fatalf("FATAL: listen (%s) failed - %s", opts.HttpAddress, err)
log.Fatalf("FATAL: could not parse %#v: %v", opts.HttpAddress, err)
}
log.Printf("listening on %s", opts.HttpAddress)
var networkType string
switch u.Scheme {
case "", "http":
networkType = "tcp"
default:
networkType = u.Scheme
}
listenAddr := strings.TrimPrefix(u.String(), u.Scheme+"://")
listener, err := net.Listen(networkType, listenAddr)
if err != nil {
log.Fatalf("FATAL: listen (%s, %s) failed - %s", networkType, listenAddr, err)
}
log.Printf("listening on %s", listenAddr)
server := &http.Server{Handler: oauthproxy}
err = server.Serve(listener)