Skip to content

Commit

Permalink
wip: allow setting a custom path
Browse files Browse the repository at this point in the history
  • Loading branch information
domenkozar committed Feb 12, 2024
1 parent f9a07c0 commit ced287c
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/Network/GRPC/Client/Connection.hs
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,7 @@ startRPC Connection{connMetaVar, connParams, connStateVar} _ callParams = do
]
, requestMetadata =
callRequestMetadata callParams
, requestPath = callPath callParams
, requestCompression =
compressionId <$> cOut
, requestAcceptCompression = Just $
Expand Down
11 changes: 8 additions & 3 deletions src/Network/GRPC/Client/Session.hs
Original file line number Diff line number Diff line change
Expand Up @@ -103,13 +103,18 @@ instance IsRPC rpc => InitiateSession (ClientSession rpc) where
(fmap getTrailersOnly . parseTrailersOnly (Proxy @rpc))
(responseHeaders info)

buildRequestInfo _ start = RequestInfo {
buildRequestInfo _ start =
let
rp = case start of
FlowStartRegular headers -> Network.GRPC.Spec.requestPath (outHeaders headers)
FlowStartNoMessages _ -> Nothing
in RequestInfo {
requestMethod = rawMethod resourceHeaders
, requestPath = rawPath resourceHeaders
, requestPath = maybe (rawPath resourceHeaders) id rp
, requestHeaders = buildRequestHeaders (Proxy @rpc) $
case start of
FlowStartRegular headers -> outHeaders headers
FlowStartNoMessages headers -> headers
FlowStartNoMessages noMsgs -> noMsgs
}
where
resourceHeaders :: RawResourceHeaders
Expand Down
4 changes: 4 additions & 0 deletions src/Network/GRPC/Spec/Call.hs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ module Network.GRPC.Spec.Call (
) where

import Data.Default
import Data.ByteString qualified as Strict

import Network.GRPC.Spec.CustomMetadata
import Network.GRPC.Spec.Timeout


{-------------------------------------------------------------------------------
Parameteres
-------------------------------------------------------------------------------}
Expand All @@ -27,6 +29,7 @@ data CallParams = CallParams {
-- its own metadata in the response: see 'responseMetadata' and
-- 'trailerMetadatda'.)
, callRequestMetadata :: [CustomMetadata]
, callPath :: Maybe Strict.ByteString
}
deriving stock (Show, Eq)

Expand All @@ -35,5 +38,6 @@ instance Default CallParams where
def = CallParams {
callTimeout = Nothing
, callRequestMetadata = []
, callPath = Nothing
}

4 changes: 4 additions & 0 deletions src/Network/GRPC/Spec/Request.hs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ data RequestHeaders = RequestHeaders {
-- | Compression used for outgoing messages
, requestCompression :: Maybe CompressionId

, requestPath :: Maybe Strict.ByteString

-- | Accepted compression algorithms for incoming messages
--
-- @Maybe (NonEmpty ..)@ is perhaps a bit strange (why not just @[]@), but
Expand Down Expand Up @@ -272,6 +274,7 @@ parseRequestHeaders proxy =
Right (Nothing :: Maybe Timeout)
:* Right ([] :: [CustomMetadata])
:* Right (Nothing :: Maybe CompressionId)
:* Right (Nothing :: Maybe Strict.ByteString)
:* Right (Nothing :: Maybe (NonEmpty CompressionId))
:* Right (Nothing :: Maybe Strict.ByteString)
:* Right (Nothing :: Maybe TraceContext)
Expand All @@ -280,6 +283,7 @@ parseRequestHeaders proxy =
( _updTimeout
:* updCustom
:* updCompression
:* updPath
:* updAcceptCompression
:* _updOverrideContentType
:* updTraceContext
Expand Down

0 comments on commit ced287c

Please sign in to comment.