|
|
@ -2,10 +2,8 @@ package http |
|
|
|
|
|
|
|
|
|
|
|
import ( |
|
|
|
import ( |
|
|
|
"context" |
|
|
|
"context" |
|
|
|
"fmt" |
|
|
|
|
|
|
|
"io" |
|
|
|
"io" |
|
|
|
"net/http" |
|
|
|
"net/http" |
|
|
|
"os" |
|
|
|
|
|
|
|
"strings" |
|
|
|
"strings" |
|
|
|
"time" |
|
|
|
"time" |
|
|
|
|
|
|
|
|
|
|
@ -37,7 +35,6 @@ func (l *Listener) Addr() net.Addr { |
|
|
|
|
|
|
|
|
|
|
|
func (l *Listener) Close() error { |
|
|
|
func (l *Listener) Close() error { |
|
|
|
if l.locker != nil { |
|
|
|
if l.locker != nil { |
|
|
|
fmt.Fprintln(os.Stderr, "RELEASE LOCK") |
|
|
|
|
|
|
|
l.locker.Release() |
|
|
|
l.locker.Release() |
|
|
|
} |
|
|
|
} |
|
|
|
return l.server.Close() |
|
|
|
return l.server.Close() |
|
|
@ -89,11 +86,11 @@ func (l *Listener) ServeHTTP(writer http.ResponseWriter, request *http.Request) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
forwardedAddrs := http_proto.ParseXForwardedFor(request.Header) |
|
|
|
forwardedAddress := http_proto.ParseXForwardedFor(request.Header) |
|
|
|
if len(forwardedAddrs) > 0 && forwardedAddrs[0].Family().IsIP() { |
|
|
|
if len(forwardedAddress) > 0 && forwardedAddress[0].Family().IsIP() { |
|
|
|
remoteAddr = &net.TCPAddr{ |
|
|
|
remoteAddr = &net.TCPAddr{ |
|
|
|
IP: forwardedAddrs[0].IP(), |
|
|
|
IP: forwardedAddress[0].IP(), |
|
|
|
Port: int(0), |
|
|
|
Port: 0, |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -165,7 +162,7 @@ func Listen(ctx context.Context, address net.Address, port net.Port, streamSetti |
|
|
|
Net: "unix", |
|
|
|
Net: "unix", |
|
|
|
}, streamSettings.SocketSettings) |
|
|
|
}, streamSettings.SocketSettings) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
newError("failed to listen on ", address).Base(err).WriteToLog(session.ExportIDToError(ctx)) |
|
|
|
newError("failed to listen on ", address).Base(err).AtError().WriteToLog(session.ExportIDToError(ctx)) |
|
|
|
return |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
locker := ctx.Value(address.Domain()) |
|
|
|
locker := ctx.Value(address.Domain()) |
|
|
@ -178,7 +175,7 @@ func Listen(ctx context.Context, address net.Address, port net.Port, streamSetti |
|
|
|
Port: int(port), |
|
|
|
Port: int(port), |
|
|
|
}, streamSettings.SocketSettings) |
|
|
|
}, streamSettings.SocketSettings) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
newError("failed to listen on ", address, ":", port).Base(err).WriteToLog(session.ExportIDToError(ctx)) |
|
|
|
newError("failed to listen on ", address, ":", port).Base(err).AtError().WriteToLog(session.ExportIDToError(ctx)) |
|
|
|
return |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -186,12 +183,12 @@ func Listen(ctx context.Context, address net.Address, port net.Port, streamSetti |
|
|
|
if config == nil { |
|
|
|
if config == nil { |
|
|
|
err = server.Serve(streamListener) |
|
|
|
err = server.Serve(streamListener) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
newError("stoping serving H2C").Base(err).WriteToLog(session.ExportIDToError(ctx)) |
|
|
|
newError("stopping serving H2C").Base(err).WriteToLog(session.ExportIDToError(ctx)) |
|
|
|
} |
|
|
|
} |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
err = server.ServeTLS(streamListener, "", "") |
|
|
|
err = server.ServeTLS(streamListener, "", "") |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
newError("stoping serving TLS").Base(err).WriteToLog(session.ExportIDToError(ctx)) |
|
|
|
newError("stopping serving TLS").Base(err).WriteToLog(session.ExportIDToError(ctx)) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
}() |
|
|
|
}() |
|
|
|