Skip to content

redirect sessions w/o trailing slash #7

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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
21 changes: 21 additions & 0 deletions server.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,17 @@ func (s *server) serveContent(w http.ResponseWriter, r *http.Request, name strin

func (s *server) handleFrontConnections() error {
router := mux.NewRouter()

router.Path("/s/{sessionID}").HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)
sessionID := vars["sessionID"]

redirectPath := "/s/" + sessionID + "/"

log.Infof("Redirecting request from: %s | %s => %s", r.RemoteAddr, r.URL.Path, redirectPath)
http.Redirect(w, r, redirectPath, http.StatusMovedPermanently)
})

router.PathPrefix("/s/{sessionID}/").HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
startTime := time.Now()
log.Infof("New front client connection: %s, from %s", r.URL.Path, r.RemoteAddr)
Expand Down Expand Up @@ -243,6 +254,16 @@ func (s *server) handleFrontConnections() error {
http.Redirect(w, r, "https://tty-share.com", http.StatusMovedPermanently)
})

// Add logging middleware
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@matthewstrasiotto I know it's been ages since you submitted this, but only now had some time to review. Sorry for the delay, and thanks for the change.

I think this part with the logging should be left out of the trailing slash change, since it's not really related

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh lol, fair enough

router.Use(func(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
// Do stuff here
log.Debugf("Request from: %s for %s", r.RemoteAddr, r.URL)
// Call the next handler, which can be another middleware in the chain, or the final handler.
next.ServeHTTP(w, r)
})
})

s.httpServer = &http.Server{
Addr: s.config.frontListenAddress,
Handler: router,
Expand Down