diff options
author | adamw <adam@warski.org> | 2017-08-10 10:31:25 +0200 |
---|---|---|
committer | adamw <adam@warski.org> | 2017-08-10 10:31:25 +0200 |
commit | ec62e95a5f827cec7ba638a41680e78592e0192c (patch) | |
tree | 3c0b5567dc136b572f4dec4cf452afbb2e6c9229 /core/src/main/scala/com/softwaremill | |
parent | d97fb63953986e26657861469e6c8e8aba70f5d9 (diff) | |
download | sttp-ec62e95a5f827cec7ba638a41680e78592e0192c.tar.gz sttp-ec62e95a5f827cec7ba638a41680e78592e0192c.tar.bz2 sttp-ec62e95a5f827cec7ba638a41680e78592e0192c.zip |
Small simplification of the withBasicBody method
Diffstat (limited to 'core/src/main/scala/com/softwaremill')
-rw-r--r-- | core/src/main/scala/com/softwaremill/sttp/RequestT.scala | 21 |
1 files changed, 9 insertions, 12 deletions
diff --git a/core/src/main/scala/com/softwaremill/sttp/RequestT.scala b/core/src/main/scala/com/softwaremill/sttp/RequestT.scala index 6b1bf0c..b785e7c 100644 --- a/core/src/main/scala/com/softwaremill/sttp/RequestT.scala +++ b/core/src/main/scala/com/softwaremill/sttp/RequestT.scala @@ -231,18 +231,15 @@ case class RequestT[U[_], T, +S]( if (hasContentType) this else contentType(ct) private def withBasicBody(body: BasicRequestBody) = { - if (hasContentType) this - else - body match { - case StringBody(_, encoding, Some(ct)) => - contentType(ct, encoding) - case body => - body.defaultContentType match { - case Some(ct) => contentType(ct) - case None => this - } - } - }.copy(body = body) + val defaultCt = body match { + case StringBody(_, encoding, Some(ct)) => + Some(contentTypeWithEncoding(ct, encoding)) + case _ => + body.defaultContentType + } + + defaultCt.fold(this)(setContentTypeIfMissing).copy(body = body) + } private def hasContentLength: Boolean = headers.exists(_._1.equalsIgnoreCase(ContentLengthHeader)) |