Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
457 views
in Technique[技术] by (71.8m points)

scala - Akka-HTTP: how to know if Content-type header was explicitly set in received response

Is the a way in akka-http to know if 'Content-type' header was explicitly set in HttpResponse that we received? From sniffed Http dump I see, that there was no 'Content-Type' header, but

httpResponse.header[`Content-Type`].get.contentType.mediaType.toString() and httpResponse.entity.getContentType().mediaType.toString

stil return application/octet-stream.

question from:https://stackoverflow.com/questions/66063753/akka-http-how-to-know-if-content-type-header-was-explicitly-set-in-received-res

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

This is default Content type not only for Akka-HTTP, but perhaps for other frameworks like Play too. Akka-http and other HTTP based technologies need to know how to parse content internally, based on this header. application/octet-stream means that it considers request body as just byte-stream. Rule of thumb: if it is possible - try to specify Content-type.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...