Skip to content
This repository has been archived by the owner on Aug 27, 2020. It is now read-only.

Commit

Permalink
use github.com/julienschmidt/httprouter
Browse files Browse the repository at this point in the history
  • Loading branch information
lzjluzijie committed Jul 15, 2018
1 parent e61b1f2 commit c0b2ae0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
12 changes: 4 additions & 8 deletions server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ import (

"crypto/tls"

"github.com/gin-gonic/gin"
"github.com/gorilla/websocket"
"github.com/juju/loggo"
"github.com/julienschmidt/httprouter"
"github.com/lzjluzijie/websocks/core"
)

Expand All @@ -33,9 +33,7 @@ type WebSocksServer struct {
Stats *core.Stats
}

func (server *WebSocksServer) HandleWebSocket(c *gin.Context) {
w := c.Writer
r := c.Request
func (server *WebSocksServer) HandleWebSocket(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
wsConn, err := server.Upgrader.Upgrade(w, r, nil)
if err != nil {
logger.Debugf(err.Error())
Expand Down Expand Up @@ -87,7 +85,7 @@ func (server *WebSocksServer) DialRemote(host string) (conn net.Conn, err error)
}

func (server *WebSocksServer) Run() (err error) {
r := gin.Default()
r := httprouter.New()
r.GET(server.Pattern, server.HandleWebSocket)

if server.ReverseProxy != "" {
Expand All @@ -96,9 +94,7 @@ func (server *WebSocksServer) Run() (err error) {
panic(err)
}
proxy := httputil.NewSingleHostReverseProxy(remote)
r.NoRoute(func(c *gin.Context) {
proxy.ServeHTTP(c.Writer, c.Request)
})
r.NotFound = proxy
}

s := http.Server{
Expand Down
6 changes: 5 additions & 1 deletion websocks.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ func main() {
cli.StringFlag{
Name: "p",
Value: "/websocks",
Usage: "server.com/pattern, like password, start with '/'",
Usage: "websocks.org/pattern",
},
cli.BoolFlag{
Name: "tls",
Expand Down Expand Up @@ -139,6 +139,10 @@ func main() {

logger.Infof("Log level %s", logger.LogLevel().String())

if pattern[0] != '/' {
pattern = "/" + pattern
}

config := server.Config{
Pattern: pattern,
ListenAddr: listenAddr,
Expand Down

0 comments on commit c0b2ae0

Please sign in to comment.