Skip to content
Permalink
Browse files

Fixed bug in ContentType.extension and better file naming in JVM Http…

…Client implementation
  • Loading branch information
darkfrog26 committed Oct 30, 2019
1 parent eabb86b commit bb653915273c789fd2acf0b07398c38113460cc2
@@ -4,7 +4,7 @@ import sbtcrossproject.CrossType

name := "youi"
organization in ThisBuild := "io.youi"
version in ThisBuild := "0.12.2"
version in ThisBuild := "0.12.5-SNAPSHOT"
scalaVersion in ThisBuild := "2.13.1"
crossScalaVersions in ThisBuild := List("2.13.1", "2.12.10")
resolvers in ThisBuild ++= Seq(
@@ -195,7 +195,9 @@ class JVMHttpClientImplementation(config: HttpClientConfig) extends HttpClientIm
} else if (contentToBytes(contentType, contentLength)) {
Content.bytes(responseBody.bytes(), contentType)
} else {
val file = File.createTempFile("youi", "client", new File(config.saveDirectory))
val suffix = contentType.extension.getOrElse("client")
if (suffix == "client") scribe.warn(s"No extension found for: $contentType")
val file = File.createTempFile("youi", s".$suffix", new File(config.saveDirectory))
IO.stream(responseBody.byteStream(), file)
Content.file(file, contentType)
}
@@ -21,7 +21,7 @@ case class ContentType(`type`: String,
}
b.toString()
}
lazy val extension: Option[String] = ContentType.mimeType2Extensions.getOrElse(`type`, Nil).headOption
lazy val extension: Option[String] = ContentType.mimeType2Extensions.getOrElse(mimeType, Nil).headOption

def withExtra(key: String, value: String): ContentType = copy(extras = extras + (key -> value))
def withCharSet(charSet: String): ContentType = withExtra("charset", charSet)
@@ -18,6 +18,10 @@ class URLSpec extends AnyWordSpec with Matchers {
val url = URL("http://www.outr.com/test?wsdl")
url.parameters.encoded should be("?wsdl")
}
"properly parse a simple HTTPS URL" in {
val url = URL("https://techcrunch.com/2019/10/13/ban-facebook-campaign-ads/?utm_medium=TCnewsletter&tpcc=TCdailynewsletter")
url.toString should be("https://techcrunch.com/2019/10/13/ban-facebook-campaign-ads/?utm_medium=TCnewsletter&tpcc=TCdailynewsletter")
}
"properly parse a simple file URL" in {
val url = URL("file:///android_asset/www/app/test.js")
url.host should be("")

0 comments on commit bb65391

Please sign in to comment.
You can’t perform that action at this time.