-
Notifications
You must be signed in to change notification settings - Fork 656
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
Showing
3 changed files
with
119 additions
and
36 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,23 @@ | ||
## Use goflyway in Caddy [beta] | ||
|
||
1. Follow the [official guide](https://github.com/mholt/caddy#build) to run a working caddy server from source | ||
2. In `caddy/caddymain/run.go`, add `_ "github.com/coyove/goflyway/cmd/gocaddyway"` | ||
2. In `caddyhttp/httpserver/plugin.go`, add `goflyway` to `directives` at about line 600. (Don't add to the bottom, it should be in front of `locale`, the order is important) | ||
2. Build caddy | ||
2. Prepare a Caddyfile and start the server, e.g.: | ||
``` | ||
http://:8100 { | ||
goflyway password | ||
proxy / http://example.com | ||
} | ||
``` | ||
2. At local: | ||
``` | ||
./goflyway -up xxx:8100 -k password | ||
``` | ||
2. Done! | ||
## Note | ||
1. TCP multiplexer is not supported | ||
2. Caddyfile hot reload is not supported, stop all and restart all |
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,58 @@ | ||
package gocaddyway | ||
|
||
import ( | ||
"net/http" | ||
|
||
"github.com/coyove/common/logg" | ||
"github.com/coyove/goflyway/proxy" | ||
"github.com/mholt/caddy" | ||
"github.com/mholt/caddy/caddyhttp/httpserver" | ||
) | ||
|
||
type gofwHandler struct { | ||
Next httpserver.Handler | ||
gofw *proxy.ProxyServer | ||
} | ||
|
||
func init() { | ||
caddy.RegisterPlugin("goflyway", caddy.Plugin{ | ||
ServerType: "http", | ||
Action: setup, | ||
}) | ||
} | ||
|
||
func setup(c *caddy.Controller) error { | ||
|
||
c.Next() | ||
if !c.NextArg() { | ||
return c.ArgErr() | ||
} | ||
|
||
cipher := proxy.NewCipher(c.Val(), proxy.FullCipher) | ||
cipher.IO.StartPurgeConns(20) | ||
cipher.IO.Logger = logg.NewLogger("off") | ||
sc := &proxy.ServerConfig{ | ||
Cipher: cipher, | ||
LBindTimeout: 10, | ||
LBindCap: 256, | ||
Logger: cipher.IO.Logger, | ||
} | ||
|
||
cfg := httpserver.GetConfig(c) | ||
mid := func(next httpserver.Handler) httpserver.Handler { | ||
server, _ := proxy.NewServer("0.0.0.0:0", sc) | ||
return gofwHandler{ | ||
Next: next, | ||
gofw: server, | ||
} | ||
} | ||
cfg.AddMiddleware(mid) | ||
return nil | ||
} | ||
|
||
func (h gofwHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) (int, error) { | ||
if h.gofw.ServeHTTPImpl(w, r) { | ||
return 0, nil | ||
} | ||
return h.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