diff --git a/README.md b/README.md index 2d648065..406a6420 100644 --- a/README.md +++ b/README.md @@ -131,6 +131,10 @@ The relayer is configured via a JSON file, the path to which is passed in via th - Additional query parameters to include in the API requests. + `"http-headers": map[string]string` + + - Additional HTTP headers to include in the API requests. + `"info-api": APIConfig` - The configuration for the Avalanche Info API node. The `InfoAPI` object has the following configuration: @@ -150,6 +154,10 @@ The relayer is configured via a JSON file, the path to which is passed in via th - Additional query parameters to include in the API requests. + `"http-headers": map[string]string` + + - Additional HTTP headers to include in the API requests. + `"storage-location": string` - The path to the directory in which the relayer will store its state. Defaults to `./awm-relayer-storage`. diff --git a/config/config.go b/config/config.go index c9c76659..dcf07ae8 100644 --- a/config/config.go +++ b/config/config.go @@ -126,6 +126,7 @@ type WarpQuorum struct { type APIConfig struct { BaseURL string `mapstructure:"base-url" json:"base-url"` QueryParams map[string]string `mapstructure:"query-parameters" json:"query-parameters"` + HTTPHeaders map[string]string `mapstructure:"http-headers" json:"http-headers"` } // Top-level configuration diff --git a/config/test_utils.go b/config/test_utils.go index e95f794d..603d8909 100644 --- a/config/test_utils.go +++ b/config/test_utils.go @@ -13,6 +13,8 @@ var ( testPk2 string = "0x12389e99c94b6912bfc12adc093c9b51124f0dc54ac7a766b2bc5ccf558d8123" queryParamKey1 string = "key1" queryParamVal1 string = "val1" + httpHeaderKey1 string = "keyheader1" + httpHeaderVal1 string = "valheader1" ) // Valid configuration objects to be used by tests in external packages @@ -24,6 +26,9 @@ var ( QueryParams: map[string]string{ queryParamKey1: queryParamVal1, }, + HTTPHeaders: map[string]string{ + httpHeaderKey1: httpHeaderVal1, + }, }, InfoAPI: &APIConfig{ BaseURL: "http://test.avax.network", diff --git a/peers/utils/utils.go b/peers/utils/utils.go index ed713f9c..e8636210 100644 --- a/peers/utils/utils.go +++ b/peers/utils/utils.go @@ -10,9 +10,12 @@ import ( // InitializeOptions initializes the rpc options for an API func InitializeOptions(apiConfig *config.APIConfig) []rpc.Option { - options := make([]rpc.Option, 0, len(apiConfig.QueryParams)) + options := make([]rpc.Option, 0, len(apiConfig.QueryParams)+len(apiConfig.HTTPHeaders)) for key, value := range apiConfig.QueryParams { options = append(options, rpc.WithQueryParam(key, value)) } + for key, value := range apiConfig.HTTPHeaders { + options = append(options, rpc.WithHeader(key, value)) + } return options }