Skip to content

Commit

Permalink
server plugin: set version and op in http request query (fatedier#1707)
Browse files Browse the repository at this point in the history
  • Loading branch information
fatedier authored Mar 20, 2020
1 parent a4b105d commit 809f517
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
2 changes: 1 addition & 1 deletion doc/server_plugin.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ HTTP path can be configured for each manage plugin in frps. We'll assume for thi
A request to the RPC server will look like:

```
POST /handler
POST /handler?version=0.1.0&op=Login
{
"version": "0.1.0",
"op": "Login",
Expand Down
6 changes: 5 additions & 1 deletion models/plugin/server/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"fmt"
"io/ioutil"
"net/http"
"net/url"
"reflect"
)

Expand Down Expand Up @@ -78,7 +79,10 @@ func (p *httpPlugin) do(ctx context.Context, r *Request, res *Response) error {
if err != nil {
return err
}
req, err := http.NewRequest("POST", p.url, bytes.NewReader(buf))
v := url.Values{}
v.Set("version", r.Version)
v.Set("op", r.Op)
req, err := http.NewRequest("POST", p.url+"?"+v.Encode(), bytes.NewReader(buf))
if err != nil {
return err
}
Expand Down
16 changes: 16 additions & 0 deletions models/plugin/server/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ func (m *Manager) Register(p Plugin) {
}

func (m *Manager) Login(content *LoginContent) (*LoginContent, error) {
if len(m.loginPlugins) == 0 {
return content, nil
}

var (
res = &Response{
Reject: false,
Expand Down Expand Up @@ -85,6 +89,10 @@ func (m *Manager) Login(content *LoginContent) (*LoginContent, error) {
}

func (m *Manager) NewProxy(content *NewProxyContent) (*NewProxyContent, error) {
if len(m.newProxyPlugins) == 0 {
return content, nil
}

var (
res = &Response{
Reject: false,
Expand Down Expand Up @@ -115,6 +123,10 @@ func (m *Manager) NewProxy(content *NewProxyContent) (*NewProxyContent, error) {
}

func (m *Manager) Ping(content *PingContent) (*PingContent, error) {
if len(m.pingPlugins) == 0 {
return content, nil
}

var (
res = &Response{
Reject: false,
Expand Down Expand Up @@ -145,6 +157,10 @@ func (m *Manager) Ping(content *PingContent) (*PingContent, error) {
}

func (m *Manager) NewWorkConn(content *NewWorkConnContent) (*NewWorkConnContent, error) {
if len(m.newWorkConnPlugins) == 0 {
return content, nil
}

var (
res = &Response{
Reject: false,
Expand Down

0 comments on commit 809f517

Please sign in to comment.