server plugin: set version and op in http request query (#1707)

This commit is contained in:
fatedier 2020-03-20 20:53:14 +08:00 committed by GitHub
parent a4b105dedb
commit 809f517db8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 22 additions and 2 deletions

View File

@ -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: A request to the RPC server will look like:
``` ```
POST /handler POST /handler?version=0.1.0&op=Login
{ {
"version": "0.1.0", "version": "0.1.0",
"op": "Login", "op": "Login",

View File

@ -21,6 +21,7 @@ import (
"fmt" "fmt"
"io/ioutil" "io/ioutil"
"net/http" "net/http"
"net/url"
"reflect" "reflect"
) )
@ -78,7 +79,10 @@ func (p *httpPlugin) do(ctx context.Context, r *Request, res *Response) error {
if err != nil { if err != nil {
return err 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 { if err != nil {
return err return err
} }

View File

@ -55,6 +55,10 @@ func (m *Manager) Register(p Plugin) {
} }
func (m *Manager) Login(content *LoginContent) (*LoginContent, error) { func (m *Manager) Login(content *LoginContent) (*LoginContent, error) {
if len(m.loginPlugins) == 0 {
return content, nil
}
var ( var (
res = &Response{ res = &Response{
Reject: false, Reject: false,
@ -85,6 +89,10 @@ func (m *Manager) Login(content *LoginContent) (*LoginContent, error) {
} }
func (m *Manager) NewProxy(content *NewProxyContent) (*NewProxyContent, error) { func (m *Manager) NewProxy(content *NewProxyContent) (*NewProxyContent, error) {
if len(m.newProxyPlugins) == 0 {
return content, nil
}
var ( var (
res = &Response{ res = &Response{
Reject: false, Reject: false,
@ -115,6 +123,10 @@ func (m *Manager) NewProxy(content *NewProxyContent) (*NewProxyContent, error) {
} }
func (m *Manager) Ping(content *PingContent) (*PingContent, error) { func (m *Manager) Ping(content *PingContent) (*PingContent, error) {
if len(m.pingPlugins) == 0 {
return content, nil
}
var ( var (
res = &Response{ res = &Response{
Reject: false, Reject: false,
@ -145,6 +157,10 @@ func (m *Manager) Ping(content *PingContent) (*PingContent, error) {
} }
func (m *Manager) NewWorkConn(content *NewWorkConnContent) (*NewWorkConnContent, error) { func (m *Manager) NewWorkConn(content *NewWorkConnContent) (*NewWorkConnContent, error) {
if len(m.newWorkConnPlugins) == 0 {
return content, nil
}
var ( var (
res = &Response{ res = &Response{
Reject: false, Reject: false,