Hi Tim,

In this case you won't be able to do that, because the Source is
materialized by the framework. I think something similar might be
achievable by creating your own marshaller. That can pre-materialize your
Source to a Publisher (Sink.publisher), rewrap it in a Source, and take the
returned Future (the materialized value) and transform it so that if it
returns false, then you just terminate the already running Source with a
Sink.ignore (otherwise actors would leak!) and return a strict HttpResponse
else return an HttpResponse wrapping the already running Source.

-Endre

On Sat, Nov 14, 2015 at 8:50 PM, Tim Harper <[email protected]> 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. Then, I'd li
>
> 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.
>
> 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 [email protected].
> To post to this group, send email to [email protected].
> Visit this group at http://groups.google.com/group/akka-user.
> For more options, visit https://groups.google.com/d/optout.
>



-- 
Akka Team
Typesafe - Reactive apps on the JVM
Blog: letitcrash.com
Twitter: @akkateam

-- 
>>>>>>>>>>      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 [email protected].
To post to this group, send email to [email protected].
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