0
votes

Using latest akka-http I want to implement an endpoint which will redirect all incoming upload file requests without consuming request entity.

Current implementation is using :

put {
  extractRequest { r: HttpRequest =>
    onComplete(r.discardEntityBytes().future) { done =>
      redirect(Uri("http://example.com"), TemporaryRedirect)
    }
  }
}

The problem is that it waits until whole http request body is received (discarded) and only after that sends redirect response. From client perspective it means uploading file twice. I tried to add withSizeLimit(0) to request entity, but it introduces early response problem.

Related documentation:

1
Are you trying to ensure that entity does not get forwarded or are you just worried about the entity size?Ramón J Romero y Vigil
I want somehow avoid sending big entity 2 times from the client if it is ignored anyway.Nikolay

1 Answers

0
votes

I did something similar, today. Are you sure that the discarding needs to be completed prior to the redirect?

How about this:

put {
  extractRequest { r: HttpRequest =>
    r.discardEntityBytes()   // runs wild

    redirect(Uri("http://example.com"), TemporaryRedirect)
  }
}

.discardEntityBytes is used to try to "cancel" unnecessary network traffic that the receiver won't need. Here, we set it up asap. It runs on the background (I hope), and returning the redirect would happen also asap.

I'd be interested to hear, whether this changed anything...