-
Notifications
You must be signed in to change notification settings - Fork 596
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
Document what to do instead, if using the (anti pattern) respondWithMediaType from Spray - Explain the benefits of marshalling #190
Comments
Yes, it is an anti-pattern we didn't manage to get rid of. Unfortunately, (as we found out too late) it was part of one of the introductory examples, which needed it to serve scala-xml literals properly as |
Yes, +1 to " |
Thanks for confirming guys! |
Added a note in |
Reopening, it was mentioned in http://akiradeveloper.hatenadiary.com/entry/2015/11/02/222054 as lack of this directive caused him to abandon akka-http (and another thing). We should re-visit the directive and explicitly explain what to do instead if we really don't want it. |
I seriously doubt that the lack of a single directive can be the single cause why anyone would not use akka-http. Especially since you can easily write this directive yourself, if you so wish, with only a few lines of code.
|
It seems the bigger problem of the blog poster was to get the entity types to work with the S3 API uploads. I guess it could be a confusion about when to use CloseDelimited vs Default but Google Translate didn't preserve enough semantics for me to understand what the real problem was. |
We tried to reach out to him (in Japanese, thanks @eed3si9n!) for more details. |
Hmm, so I take it that those less capable clients are relevant and we should support them? If so, then we’ll need to make it possible and document it. Otherwise we just need to document it. |
As I understood it the problem was in writing a client for S3 uploads. Using chunked uploads with S3 seems to be possible but is quite complex (due to having to use an extra framing protocol layer in addition to the HTTP chunking to provide signatures). I guess one of those things was the problem. However, none of these problems are problems of akka-http but these are all limits inherent in HTTP. We tried to model everything that is available in HTTP by the HttpEntity ADT which is very explicit in what it needs and provides. AFAIK we support all the modes that are possible with HTTP. We already have some documentation about the entity types. To be able to improve the documentation we would need to know more clearly what exactly the problem was. |
Yes. The implied "client software" that doesn't handle chunked response seems to be Amazon S3. Maybe he meant to say "peer." In any case, I think he's trying to call Complete Multipart Upload, which seems to require |
So, this is a restriction from S3 not from akka-http, right? If S3 requires a Content-Length you need to compute it somehow and use an HttpEntity.Default regardless from where the actual data comes. |
It's a combination of both since Spray was able to handle it by returning Content-Length > 0 with CloseDelimited, and now he's looking into other web frameworks. |
No, there was no CloseDelimited in spray. If you want to supply a Content-Length, HttpEntity.Default is the right choice. |
FWIW we use |
Hi all, I've gone over the conversation in this thread and the linked threads and would like to pose a question. I have an API that creates an object, but only knows how to answer when the client Based on the answers to this question on StackOverflow, I created the following to wrap around my route: extract(_.request.getHeader(classOf[Accept])) { accept =>
if (!accept.isPresent || accept.get().acceptsAll() || accept.get().mediaRanges.exists(_.matches(MediaTypes.`application/json`))) {
// My routes here...
} else {
reject(UnacceptedResponseContentTypeRejection(Set(ContentNegotiator.Alternative(MediaTypes.`application/json`))))
}
} This works, but I have two questions:
|
Hi @omervk, yeah that's the current behaviour indeed (see also akka/akka#16974 ) and it's something we'd like to improve (make the marshallers more lazy). Please track that other ticket too to get status updates on it (or help out if you can!) |
Thanks! 👍 |
can someone please show how an implementation of respondWithMediaType for akka-http would look? copying the one from spray doesn't work, as the data types have changed, and i'm not familiar enough with akka-http to know how to rewrite it. our code base unfortunately has tons of respondWithMediaType, so we really need this in order to upgrade, as it's not realistical to rewrite everything at once here's the spray implementation for reference
|
@ktoso could you please demonstrate how to implement this directive in akka-http as you suggested earlier in the thread? it would help migration a lot |
Thursday Oct 01, 2015 at 12:35 GMT
Originally opened as akka/akka#18625
Hi @sirthias @jrudolph,
I realised we don't have
respondWithMediaType
ported to Akka HTTP and am expecting that this is because we want people to rely on using the content type negotiation that HTTP does instead of baking their own using this directive...?I'd like to confirm my thinking about it so I can sleep peacefully at night 😉
Refs:
The text was updated successfully, but these errors were encountered: