Skip to content

Commit

Permalink
code(connector/server) - add injection into json body + headers key
Browse files Browse the repository at this point in the history
  • Loading branch information
PxyUp committed Nov 3, 2024
1 parent 3ebb7df commit b73dd5b
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 10 deletions.
12 changes: 7 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -368,19 +368,21 @@ Connector type which fetch data using golang http.Client(server side request lik

```go
type ServerConnectorConfig struct {
Method string `json:"method" yaml:"method"`
Headers map[string]string `yaml:"headers" json:"headers"`
Timeout uint32 `yaml:"timeout" json:"timeout"`
Body string `yaml:"body" json:"body"`
Method string `json:"method" yaml:"method"`
Headers map[string]string `yaml:"headers" json:"headers"`
Timeout uint32 `yaml:"timeout" json:"timeout"`
JsonRawBody json.RawMessage `json:"json_raw_body" yaml:"json_raw_body"`
Body string `yaml:"body" json:"body"`

Proxy *ProxyConfig `yaml:"proxy" json:"proxy"`
}
```

- Method - supported all http methods: GET, POST, PUT, DELETE, PATCH, OPTIONS, HEAD
- Headers - predefine headers for using during request [can be injected into value](#placeholder-list)
- Headers - predefine headers for using during request [can be injected into key/value](#placeholder-list)
- Timeout[sec] - default 60sec timeout or used provided
- Body - body of the request, parsed value [can be injected](#placeholder-list)
- JsonRawBody - body of the request in json format; value [can be injected](#placeholder-list)
- Proxy - setup proxy for request [config](#proxy-config)

Example:
Expand Down
9 changes: 5 additions & 4 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,10 +167,11 @@ type ChromiumConfig struct {
}

type ServerConnectorConfig struct {
Method string `json:"method" yaml:"method"`
Headers map[string]string `yaml:"headers" json:"headers"`
Timeout uint32 `yaml:"timeout" json:"timeout"`
Body string `yaml:"body" json:"body"`
Method string `json:"method" yaml:"method"`
Headers map[string]string `yaml:"headers" json:"headers"`
Timeout uint32 `yaml:"timeout" json:"timeout"`
JsonRawBody json.RawMessage `json:"json_raw_body" yaml:"json_raw_body"`
Body string `yaml:"body" json:"body"`

Proxy *ProxyConfig `yaml:"proxy" json:"proxy"`
}
Expand Down
6 changes: 5 additions & 1 deletion pkg/connectors/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ func (api *apiConnector) GetWithHeaders(parsedValue builder.Interfacable, index

func (api *apiConnector) get(parsedValue builder.Interfacable, index *uint32, input builder.Interfacable) (http.Header, []byte, error) {
formattedBody := utils.Format(api.cfg.Body, parsedValue, index, input)
if api.cfg.JsonRawBody != nil && len(api.cfg.JsonRawBody) > 0 {
formattedBody = utils.Format(string(api.cfg.JsonRawBody), parsedValue, index, input)
}

formattedURL := utils.Format(api.url, parsedValue, index, input)

if formattedURL == "" {
Expand All @@ -89,7 +93,7 @@ func (api *apiConnector) get(parsedValue builder.Interfacable, index *uint32, in
}

for k, v := range api.cfg.Headers {
req.Header.Add(k, utils.Format(v, parsedValue, index, input))
req.Header.Add(utils.Format(k, parsedValue, index, input), utils.Format(v, parsedValue, index, input))
}

client := http_client.GetDefaultClient()
Expand Down

0 comments on commit b73dd5b

Please sign in to comment.