Fixes to HTTP request recording in the Data Connector agent test suite

PR-URL: https://github.com/hasura/graphql-engine-mono/pull/9394
GitOrigin-RevId: 873dc4e8ec744013f8303d197a91ec499e6a9c66
This commit is contained in:
Daniel Chambers 2023-06-03 00:33:17 +10:00 committed by hasura-bot
parent f04d2950f2
commit e2345fb3bb
2 changed files with 9 additions and 4 deletions

View File

@ -36,6 +36,7 @@ import Data.Text qualified as Text
import GHC.Stack (HasCallStack)
import Hasura.Backends.DataConnector.API qualified as API
import Network.HTTP.Client qualified as HttpClient
import Network.HTTP.Client.Internal qualified as HttpClient
import Network.HTTP.Types (HeaderName, Method, Status (..), statusIsSuccessful)
import Servant.API (NamedRoutes)
import Servant.Client (BaseUrl, Client, Response, defaultMakeClientRequest, hoistClient, mkClientEnv, runClientM)
@ -68,7 +69,8 @@ mkHttpClientManager sensitiveOutputHandling agentAuthKey =
in liftIO $ HttpClient.newManager settings
addLicenseKeyHeader :: AgentAuthKey -> HttpClient.Request -> HttpClient.Request
addLicenseKeyHeader (AgentAuthKey eeKey) r = r {HttpClient.requestHeaders = (eeLicenseKeyHeader, eeKey) : HttpClient.requestHeaders r}
addLicenseKeyHeader (AgentAuthKey eeKey) r =
r {HttpClient.requestHeaders = (eeLicenseKeyHeader, eeKey) : filter (\(h, _) -> h /= eeLicenseKeyHeader) (HttpClient.requestHeaders r)}
addHeaderRedaction :: SensitiveOutputHandling -> HttpClient.Request -> HttpClient.Request
addHeaderRedaction sensitiveOutputHandling request =
@ -154,7 +156,10 @@ runRequestAcceptStatus' acceptStatus request = do
let clientRequest = addHeaderRedaction _accSensitiveOutputHandling $ defaultMakeClientRequest _accBaseUrl request
testFolder <- getCurrentFolder
for_ testFolder $ HttpFile.writeRequest _accBaseUrl clientRequest filenamePrefix
-- HttpClient modifies the request with settings from the Manager before it sends it. To log these modifications
-- correctly, we'll manually perform them and then record the modified request
(_, modifiedRequest) <- liftIO $ HttpClient.getModifiedRequestManager _accHttpManager clientRequest
for_ testFolder $ HttpFile.writeRequest _accBaseUrl modifiedRequest filenamePrefix
incrementRequestCounter
let redactResponseBody =

View File

@ -23,7 +23,7 @@ import Data.Text.Lazy.Encoding qualified as LazyText
import Data.Text.Lazy.IO qualified as LazyText
import Network.HTTP.Client qualified as HttpClient
import Network.HTTP.Types (Header, Status (..))
import Servant.Client (BaseUrl, showBaseUrl)
import Servant.Client (BaseUrl (baseUrlPath), showBaseUrl)
import System.FilePath ((</>))
import Prelude
@ -43,7 +43,7 @@ writeRequest baseUrl request fileNamePrefix testFolder = do
requestLine = method <> " " <> requestBaseUrl <> requestPath <> "\n"
requestBaseUrl :: TextBuilder.Builder
requestBaseUrl = TextBuilder.fromString $ showBaseUrl baseUrl
requestBaseUrl = TextBuilder.fromString $ showBaseUrl (baseUrl {baseUrlPath = ""})
requestPath :: TextBuilder.Builder
requestPath = bsToBuilder $ HttpClient.path request