Skip to content

Commit

Permalink
Export proxy request and response
Browse files Browse the repository at this point in the history
  • Loading branch information
thedae committed Nov 21, 2024
1 parent 58372c7 commit d711c2c
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 28 deletions.
32 changes: 16 additions & 16 deletions proxy/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
)

func registerRequestTable(req *proxy.Request, b *binder.Binder) {
r := &request{req}
r := &ProxyRequest{req}

t := b.Table("request")

Expand All @@ -30,14 +30,14 @@ func registerRequestTable(req *proxy.Request, b *binder.Binder) {
t.Dynamic("body", r.body)
}

type request struct {
type ProxyRequest struct {
*proxy.Request
}

var errRequestExpected = errors.New("request expected")

func (*request) method(c *binder.Context) error {
req, ok := c.Arg(1).Data().(*request)
func (*ProxyRequest) method(c *binder.Context) error {
req, ok := c.Arg(1).Data().(*ProxyRequest)
if !ok {
return errRequestExpected
}
Expand All @@ -51,8 +51,8 @@ func (*request) method(c *binder.Context) error {
return nil
}

func (*request) path(c *binder.Context) error {
req, ok := c.Arg(1).Data().(*request)
func (*ProxyRequest) path(c *binder.Context) error {
req, ok := c.Arg(1).Data().(*ProxyRequest)
if !ok {
return errRequestExpected
}
Expand All @@ -66,8 +66,8 @@ func (*request) path(c *binder.Context) error {
return nil
}

func (*request) query(c *binder.Context) error {
req, ok := c.Arg(1).Data().(*request)
func (*ProxyRequest) query(c *binder.Context) error {
req, ok := c.Arg(1).Data().(*ProxyRequest)
if !ok {
return errRequestExpected
}
Expand All @@ -81,8 +81,8 @@ func (*request) query(c *binder.Context) error {
return nil
}

func (*request) url(c *binder.Context) error {
req, ok := c.Arg(1).Data().(*request)
func (*ProxyRequest) url(c *binder.Context) error {
req, ok := c.Arg(1).Data().(*ProxyRequest)
if !ok {
return errRequestExpected
}
Expand All @@ -101,8 +101,8 @@ func (*request) url(c *binder.Context) error {
return nil
}

func (*request) params(c *binder.Context) error {
req, ok := c.Arg(1).Data().(*request)
func (*ProxyRequest) params(c *binder.Context) error {
req, ok := c.Arg(1).Data().(*ProxyRequest)
if !ok {
return errRequestExpected
}
Expand All @@ -118,8 +118,8 @@ func (*request) params(c *binder.Context) error {
return nil
}

func (*request) headers(c *binder.Context) error {
req, ok := c.Arg(1).Data().(*request)
func (*ProxyRequest) headers(c *binder.Context) error {
req, ok := c.Arg(1).Data().(*ProxyRequest)
if !ok {
return errRequestExpected
}
Expand All @@ -142,8 +142,8 @@ func (*request) headers(c *binder.Context) error {
return nil
}

func (*request) body(c *binder.Context) error {
req, ok := c.Arg(1).Data().(*request)
func (*ProxyRequest) body(c *binder.Context) error {
req, ok := c.Arg(1).Data().(*ProxyRequest)
if !ok {
return errRequestExpected
}
Expand Down
24 changes: 12 additions & 12 deletions proxy/response.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
)

func registerResponseTable(resp *proxy.Response, b *binder.Binder) {
r := &response{resp}
r := &ProxyResponse{resp}
if r.Metadata.Headers == nil {
r.Metadata.Headers = map[string][]string{}
}
Expand All @@ -33,14 +33,14 @@ func registerResponseTable(resp *proxy.Response, b *binder.Binder) {
t.Dynamic("body", r.body)
}

type response struct {
type ProxyResponse struct {
*proxy.Response
}

var errResponseExpected = errors.New("response expected")

func (*response) isComplete(c *binder.Context) error {
resp, ok := c.Arg(1).Data().(*response)
func (*ProxyResponse) isComplete(c *binder.Context) error {
resp, ok := c.Arg(1).Data().(*ProxyResponse)
if !ok {
return errResponseExpected
}
Expand All @@ -54,8 +54,8 @@ func (*response) isComplete(c *binder.Context) error {
return nil
}

func (*response) statusCode(c *binder.Context) error {
resp, ok := c.Arg(1).Data().(*response)
func (*ProxyResponse) statusCode(c *binder.Context) error {
resp, ok := c.Arg(1).Data().(*ProxyResponse)
if !ok {
return errResponseExpected
}
Expand All @@ -69,8 +69,8 @@ func (*response) statusCode(c *binder.Context) error {
return nil
}

func (*response) headers(c *binder.Context) error {
resp, ok := c.Arg(1).Data().(*response)
func (*ProxyResponse) headers(c *binder.Context) error {
resp, ok := c.Arg(1).Data().(*ProxyResponse)
if !ok {
return errResponseExpected
}
Expand All @@ -91,8 +91,8 @@ func (*response) headers(c *binder.Context) error {
return nil
}

func (*response) body(c *binder.Context) error {
resp, ok := c.Arg(1).Data().(*response)
func (*ProxyResponse) body(c *binder.Context) error {
resp, ok := c.Arg(1).Data().(*ProxyResponse)
if !ok {
return errResponseExpected
}
Expand All @@ -112,8 +112,8 @@ func (*response) body(c *binder.Context) error {
return nil
}

func (*response) data(c *binder.Context) error {
resp, ok := c.Arg(1).Data().(*response)
func (*ProxyResponse) data(c *binder.Context) error {
resp, ok := c.Arg(1).Data().(*ProxyResponse)
if !ok {
return errResponseExpected
}
Expand Down

0 comments on commit d711c2c

Please sign in to comment.