Discard HTTP Entity with conditional directive

Hello experts,

My service is using akka-http’s conditional cache directive. The Etag/Last Updated value is received from one of the downstream services along with a stream for response body.

I’m facing an issue that when the user receives 304 status code from the server the Source for the response body is never piped to a Sink and therefore never properly consumed.

What is the recommended way of closing dangling streams after conditional directive handles the response?

@akka-team

Could you help me out with this issue?

Thanks for the report, @bandreiev. That sounds like a bug, can you file an issue / PR? I think in complete403 and complete412 of CacheConditionDirectives.scala we should make sure that the original response is discarded.

That said, having a quick look at the code, I’m not sure it is intended that the inner route is even run? Can you post a code snippet that demonstrates the problem?

@jrudolph

Our service is doing something like this:

      pathPrefix("getValue") {
        val response = Http().singleRequest(HttpRequest(uri = "https://google.com"))
        onSuccess(response) { response =>
          conditional(response.header[ETag].map(_.etag), lastModified = None) {
            complete {
              response
            }
          }
        }
      }

We need to send the request to the downstream service to figure out the etag - and on success path the downstream response is a significant portion of our service response.

Any recommendations on this issue?

Regards,
Kyrylo