Can't see Content-Type in HttpRequest's header list

89 views
Skip to first unread message

Akira Hayakawa

unread,
Nov 4, 2015, 10:06:49 AM11/4/15
to Akka User List
I am moving from spray to akka-http and I am looking at a subtle but bewildering change regarding the Content-Type in HttpRequest.

In spray, it looked like this

HttpRequest(PUT,http://localhost:8080/mybucket1/,List(Host: localhost:8080, Authorization: AWS BCDEFGHIJKLMNOPQRSTA:LLUwDm85x8uWBWsu4Vgx8FK1Hec=, User-Agent: aws-sdk-java/1.10.12 Mac_OS_X/10.10 Java_HotSpot(TM)_64-Bit_Server_VM/25.45-b02/1.8.0_45, Date: Tue, 03 Nov 2015 08:46:17 GMT, Content-Type: application/x-www-form-urlencoded; charset=UTF-8, Content-Length: 0, Connection: Keep-Alive),Empty,HTTP/1.1)

But in akka-http, the same request in client-side reached to server looks different (port number changed). The request is made by aws-sdk-java of the same version that makes a bucket "mybucket1".

HttpRequest(HttpMethod(PUT),http://localhost:9000/mybucket1/,List(Host: localhost:9000, authorization: AWS BCDEFGHIJKLMNOPQRSTA:j8581UwAQuUcIbJ109TfpUZCNMk=, user-agent: aws-sdk-java/1.10.12 Mac_OS_X/10.10 Java_HotSpot(TM)_64-Bit_Server_VM/25.45-b02/1.8.0_45, Date: Tue, 03 Nov 2015 08:38:24 GMT, Connection: Keep-Alive),HttpEntity.Strict(application/x-www-form-urlencoded; charset=UTF-8,ByteString()),HttpProtocol(HTTP/1.1))

You can see that Content-Type moved from header list to HttpEntity.

Is this intended so Content-Type is modeled into HttpEntity in both HttpRequest and HttpResponse?


Akira Hayakawa

unread,
Nov 8, 2015, 3:29:25 AM11/8/15
to Akka User List
OK. I see that Content-Type is modeled into Entity.

But, this is harmful if you try to implement S3-compatible storage because its signature calculation depends on Content-Type value on the client side.

With some works it's revealed that akka-http puts versatile "application/octet-stream" type if the Content-Type is empty. The followings are requests in spray and akka-http with the same test.

spray:
HttpRequest(PUT,http://localhost:8080/mybucket/a/b?AWSAccessKeyId=BCDEFGHIJKLMNOPQRSTA&Expires=1446974354&Signature=UTG4TLzkqJDKi4pWR%2BQ4h6V5JEo%3D,List(Content-Length: 14, Host: localhost:8080, Connection: Keep-Alive, User-Agent: Apache-HttpClient/4.5.1 (Java/1.8.0_45), Accept-Encoding: gzip, deflate),HttpEntity(application/octet-stream,We love Scala!),HTTP/1.1)

akka-http:
HttpRequest(HttpMethod(PUT),http://localhost:9000/mybucket/a/b?AWSAccessKeyId=BCDEFGHIJKLMNOPQRSTA&Expires=1446974407&Signature=jrLVl0YthTkoV9O640or0T533WM%3D,List(Host: localhost:9000, Connection: Keep-Alive, User-Agent: Apache-HttpClient/4.5.1 (Java/1.8.0_45), Accept-Encoding: gzip, deflate),HttpEntity.Strict(application/octet-stream,ByteString(87, 101, 32, 108, 111, 118, 101, 32, 83, 99, 97, 108, 97, 33)),HttpProtocol(HTTP/1.1))

I think this is kind of bug that akka-http puts octet-stream as the Content-Type although the spray puts none on headers. The problem is that we can't tell adding octet-stream to Http headers is client's intention or not.

I suggest we need a config option that tells akka-http to explicitly copy the Content-Type of the received request (from client) to the headers member, without any selfish interpretation.

Akira Hayakawa

unread,
Nov 8, 2015, 3:48:36 AM11/8/15
to Akka User List
  def contentType(cth: Option[`Content-Type`]) = cth match {
   
case Some(x) x.contentType
   
case None     ContentTypes.`application/octet-stream`
 
}

I suspect this code in HttpMessageParser is the one that sets the default Content-Type that's harmful.

I guess this "cth" is of what's parsed from the raw http request. If so, this code says that if Content-Type is unseen it sets octet-stream. What is the rational behind this?

It should be ContentTypes.NoContentType, I guess.


Viktor Klang

unread,
Nov 8, 2015, 7:28:52 AM11/8/15
to Akka User List

http://stackoverflow.com/questions/5661596/do-i-need-a-content-type-for-http-get-requests

--
>>>>>>>>>> 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+...@googlegroups.com.
To post to this group, send email to akka...@googlegroups.com.
Visit this group at http://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.

Akira Hayakawa

unread,
Nov 8, 2015, 9:57:27 PM11/8/15
to akka...@googlegroups.com
With some fixes on the client side explicitly adding Content-Type now works. Thanks Viktor.

You received this message because you are subscribed to a topic in the Google Groups "Akka User List" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/akka-user/qPWokQsZypw/unsubscribe.
To unsubscribe from this group and all its topics, send an email to akka-user+...@googlegroups.com.

To post to this group, send email to akka...@googlegroups.com.
Visit this group at http://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.



--
Akira Hayakawa

Viktor Klang

unread,
Nov 9, 2015, 3:21:04 AM11/9/15
to Akka User List

Happy hAkking!

Reply all
Reply to author
Forward
0 new messages