Skip to content

Commit

Permalink
Disable goproxy logs and stop CollectJsonKeys from panicing
Browse files Browse the repository at this point in the history
  • Loading branch information
stoyan.kirov committed Aug 12, 2020
1 parent 7339b86 commit 8f9d3bb
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 2 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ module github.com/ctoyan/ponieproxy

go 1.14

require github.com/elazarl/goproxy v0.0.0-20200803153952-ec485169a1eb
require github.com/elazarl/goproxy v0.0.0-20200809112317-0581fc3aee2d
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ github.com/elazarl/goproxy v0.0.0-20200710112657-153946a5f232 h1:Ul7d4+sh+oC/QYz
github.com/elazarl/goproxy v0.0.0-20200710112657-153946a5f232/go.mod h1:Ro8st/ElPeALwNFlcTpWmkr6IoMFfkjXAvTHpevnDsM=
github.com/elazarl/goproxy v0.0.0-20200803153952-ec485169a1eb h1:72ezW27Q4wBH6pEPvByLnvqSby5T53BtbWoetF6A5QE=
github.com/elazarl/goproxy v0.0.0-20200803153952-ec485169a1eb/go.mod h1:Ro8st/ElPeALwNFlcTpWmkr6IoMFfkjXAvTHpevnDsM=
github.com/elazarl/goproxy v0.0.0-20200809112317-0581fc3aee2d h1:rtM8HsT3NG37YPjz8sYSbUSdElP9lUsQENYzJDZDUBE=
github.com/elazarl/goproxy v0.0.0-20200809112317-0581fc3aee2d/go.mod h1:Ro8st/ElPeALwNFlcTpWmkr6IoMFfkjXAvTHpevnDsM=
github.com/elazarl/goproxy/ext v0.0.0-20190711103511-473e67f1d7d2 h1:dWB6v3RcOy03t/bUadywsbyrQwCqZeNIEX6M1OtSZOM=
github.com/elazarl/goproxy/ext v0.0.0-20190711103511-473e67f1d7d2/go.mod h1:gNh8nYJoAm43RfaxurUnxr+N1PwuFV3ZMl/efxlIlY8=
github.com/rogpeppe/go-charset v0.0.0-20180617210344-2471d30d28b4/go.mod h1:qgYeAmZ5ZIpBWTGllZSQnw97Dj+woV0toclVaRGI8pc=
6 changes: 6 additions & 0 deletions internal/ponieproxy/proxy.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package ponieproxy

import (
"io/ioutil"
"log"

"github.com/ctoyan/ponieproxy/filters"
"github.com/ctoyan/ponieproxy/internal/config"
"github.com/elazarl/goproxy"
Expand All @@ -16,6 +19,9 @@ type PonieProxy struct {
func Init() *PonieProxy {
setCA(caCert, caKey)
proxy := goproxy.NewProxyHttpServer()
// Disable proxy logs
proxy.Logger = log.New(ioutil.Discard, "", log.LstdFlags)

proxy.OnRequest().HandleConnect(goproxy.AlwaysMitm)

pp := new(PonieProxy)
Expand Down
10 changes: 9 additions & 1 deletion internal/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,21 @@ func UnmarshalReqBody(reqBody string) (unmarshaled map[string]interface{}, err e
*/
func CollectJsonKeys(json map[string]interface{}, reqJsonKeys map[string]struct{}) map[string]struct{} {
for k, v := range json {
if v == nil {
return reqJsonKeys
}
rt := reflect.TypeOf(v)
switch rt.Kind() {
// if value is a slice of map[string]interface{} iterate over it again
case reflect.Slice:
s := reflect.ValueOf(v)
for i := 0; i < s.Len(); i++ {
CollectJsonKeys(s.Index(i).Interface().(map[string]interface{}), reqJsonKeys)
el, ok := s.Index(i).Interface().(map[string]interface{})
if ok {
CollectJsonKeys(el, reqJsonKeys)
}
}
// if not - all keys of other value types are added
default:
if _, ok := reqJsonKeys[k]; !ok {
reqJsonKeys[k] = struct{}{}
Expand Down

0 comments on commit 8f9d3bb

Please sign in to comment.