Skip to content

Commit

Permalink
[RelayMiner] Support https backend urls (#507)
Browse files Browse the repository at this point in the history
  • Loading branch information
red-0ne committed Apr 26, 2024
1 parent b96f7bb commit aba098d
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
6 changes: 3 additions & 3 deletions pkg/relayer/config/proxy_http_config_parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ func (serverConfig *RelayMinerServerConfig) parseHTTPServerConfig(
return nil
}

// parseHTTPSupplierConfig populates the supplier fields of the target structure
// that are relevant to "http" specific service configurations.
// parseSupplierBackendUrl populates the supplier fields of the target structure
// that are relevant to "http" and "https" backend url service configurations.
// This function alters the target RelayMinerSupplierServiceConfig structure
// as a side effect.
func (supplierServiceConfig *RelayMinerSupplierServiceConfig) parseHTTPSupplierConfig(
func (supplierServiceConfig *RelayMinerSupplierServiceConfig) parseSupplierBackendUrl(
yamlSupplierServiceConfig YAMLRelayMinerSupplierServiceConfig,
) error {
// Check if the supplier backend url is empty
Expand Down
4 changes: 2 additions & 2 deletions pkg/relayer/config/supplier_hydrator.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,10 @@ func (supplierConfig *RelayMinerSupplierConfig) HydrateSupplier(
// by their own functions.
supplierConfig.ServiceConfig = &RelayMinerSupplierServiceConfig{}
switch backendUrl.Scheme {
case "http":
case "http", "https":
supplierConfig.ServerType = RelayMinerServerTypeHTTP
if err := supplierConfig.ServiceConfig.
parseHTTPSupplierConfig(yamlSupplierConfig.ServiceConfig); err != nil {
parseSupplierBackendUrl(yamlSupplierConfig.ServiceConfig); err != nil {
return err
}
default:
Expand Down
16 changes: 15 additions & 1 deletion pkg/relayer/proxy/synchronous.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bytes"
"compress/gzip"
"context"
"crypto/tls"
"fmt"
"io"
"net/http"
Expand Down Expand Up @@ -277,8 +278,21 @@ func (sync *synchronousRPCServer) serveHTTP(
relayHTTPRequest.Header.Add(key, value)
}

// Configure the HTTP client to use the appropriate transport based on the
// backend URL scheme.
var client *http.Client
switch serviceConfig.BackendUrl.Scheme {
case "https":
transport := &http.Transport{
TLSClientConfig: &tls.Config{},
}
client = &http.Client{Transport: transport}
default:
client = http.DefaultClient
}

// Send the relay request to the native service.
httpResponse, err := http.DefaultClient.Do(relayHTTPRequest)
httpResponse, err := client.Do(relayHTTPRequest)
if err != nil {
return nil, err
}
Expand Down

0 comments on commit aba098d

Please sign in to comment.