-
Notifications
You must be signed in to change notification settings - Fork 309
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Preserved request metadata in response #2146
Conversation
import sttp.client4.Response | ||
import sttp.model._ | ||
|
||
private[sttp] object TestResponse { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe let's call it ResponseStub
, keeping the terminology consistent with BackendStub
? Also, this should be public?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah good idea with naming, as for public hmmm not sure if we want it to be expose to users ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah we do, it was exposed so far, and the idea is to use it when defining the behavior of a backend stub
/** Mainly useful in tests using [[sttp.client4.testing.SttpBackendStub]], when creating stub responses. | ||
*/ | ||
val ExampleGet: RequestMetadata = new RequestMetadata { | ||
val emptyGet: RequestMetadata = new RequestMetadata { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess we should remove all of these methods from Response
once TestResposne
is there?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah sorry, we should only keep the helper methods, but with requestMetadata: RequestMetadata
. We should move emptyGet
, though, which kind of is the point of the issue that is being fixed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
emptyGet
or whatever the name should still live in ResponseStub
/TestResponse
. The point of the issue is that this shouldn't be exposed in Response
, but explicitly marked as a test-only thing. In a backend stub, we can of course use a ResponseStub
@@ -77,7 +77,7 @@ abstract class AbstractBackendStub[F[_], P]( | |||
def thenRespond[T](body: T, statusCode: StatusCode): Self = thenRespond(Response[T](body, statusCode)) | |||
def thenRespond[T](resp: => Response[T]): Self = { | |||
val m: PartialFunction[GenericRequest[_, _], F[Response[_]]] = { | |||
case r if p(r) => monad.eval(resp) | |||
case r if p(r) => monad.eval(resp.copy(request = r.onlyMetadata)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
would be good to have a test for this
# Conflicts: # observability/prometheus-backend/src/test/scala/sttp/client4/prometheus/PrometheusBackendTest.scala
Great, thanks! |
closes #1719 #2106