I read enough source code to be able to answer my own question:

The stream still isn't materialized at this point, where the StatusCode and 
headers are already known.

https://github.com/akka/akka/blob/releasing-akka-stream-and-http-experimental-2.0-M1/akka-http-core/src/main/scala/akka/http/impl/engine/rendering/HttpResponseRendererFactory.scala#L59

Reasoning about it further, allowing the materialized type of the 
HttpEntity.Chunked stream to inform the status code would problematic, 
considering that some status codes (like, 204 - No Content) don't allow for 
response entities.

So, I'll plan around this.

Akka is simply great, great, great. Thanks for doing such thoughtful design 
and caring about correctness.

On Saturday, November 14, 2015 at 12:54:04 PM UTC-7, Tim Harper wrote:
>
> Hi,
>
> TLDR: I'd like to use the materialized value of a stream to decide the 
> HttpResponse code.
>
> Presently, I use a ToEntityMarshaller which marshals to:
> HttpEntity.Chunked(_, Source[Chunk, Future[Boolean]])
>
> The Materialized Future[Boolean] indicates whether the stream was 
> completely empty which is knowable as soon as an instance of the Source is 
> run.
>
> Since streams can be transformed multiple ways, and run multiple times, 
> I'd prefer to have the state which indicates whether the stream is empty 
> come from a materialized stream.
>
> So, what I'd like to know, is if it's possible to use the stream 
> materialized value to inform the response headers / code in a 
> ToResponseMarshallable. As far as I can tell, from reading the source 
> code of akka-http, it doesn't seem possible (a layer later in the process 
> materializes the Source[Chunk, Any] AFTER an HttpResponse (containing the 
> code, headers, and entity) is fully generated.
>
> If this is possible, can someone point me to an example?
>
> By the way, the stream integration for Akka HTTP is really, really 
> amazing! Great work on it, Akka devs! I'm planning to blog about this and 
> do a little walk-through tutorial on how to content-negotiated streaming of 
> either JSON or protocol buffers.
>
> Thanks!
>
> Tim
>

-- 
>>>>>>>>>>      Read the docs: http://akka.io/docs/
>>>>>>>>>>      Check the FAQ: 
>>>>>>>>>> http://doc.akka.io/docs/akka/current/additional/faq.html
>>>>>>>>>>      Search the archives: https://groups.google.com/group/akka-user
--- 
You received this message because you are subscribed to the Google Groups "Akka 
User List" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to akka-user+unsubscr...@googlegroups.com.
To post to this group, send email to akka-user@googlegroups.com.
Visit this group at http://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.

Reply via email to