-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
navigaid
committed
Apr 13, 2024
1 parent
1c5c176
commit 22ef08d
Showing
2 changed files
with
40 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package mini | ||
|
||
import ( | ||
"log/slog" | ||
"net" | ||
"net/http" | ||
|
||
"github.com/webteleport/relay" | ||
"github.com/webteleport/ufo/apps/relay/envs" | ||
"github.com/webteleport/utils" | ||
) | ||
|
||
func listenHTTP(handler http.Handler) error { | ||
slog.Info("listening on HTTP http://" + envs.HOST + envs.HTTP_PORT) | ||
ln, err := net.Listen("tcp4", envs.HTTP_PORT) | ||
if err != nil { | ||
return err | ||
} | ||
return http.Serve(ln, handler) | ||
} | ||
|
||
func Run([]string) (err error) { | ||
sm := relay.NewSessionManager(envs.HOST) | ||
|
||
var dsm http.Handler = sm | ||
// Set the Alt-Svc header for UDP port discovery && http3 bootstrapping | ||
dsm = AltSvcMiddleware(dsm) | ||
dsm = utils.GinLoggerMiddleware(dsm) | ||
|
||
return listenHTTP(dsm) | ||
} | ||
|
||
func AltSvcMiddleware(next http.Handler) http.Handler { | ||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | ||
w.Header().Set("Alt-Svc", envs.ALT_SVC) | ||
next.ServeHTTP(w, r) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters