From f164efa93367b546e5432f4bbc0e9b27097208fb Mon Sep 17 00:00:00 2001 From: Jakob Odersky Date: Sun, 3 Nov 2024 11:17:52 +0100 Subject: [PATCH] Drop content-length header in compressed decorator Since we're compressing data on the fly, we can't know the content-length ahead of time. While requests 0.8.0 (which uses the JDK's URLConnection) allowed this, requests 0.9.0 (which uses the new HttpClient API) is stricter and fails. Also upgrade requests to 0.9.0 --- build.mill | 2 +- cask/src/cask/decorators/compress.scala | 8 ++++++-- example/compress/package.mill | 2 +- example/compress2/package.mill | 2 +- example/compress3/package.mill | 2 +- example/cookies/package.mill | 2 +- example/decorated/package.mill | 2 +- example/decorated2/package.mill | 2 +- example/decoratedContext/package.mill | 2 +- example/endpoints/package.mill | 2 +- example/formJsonPost/package.mill | 2 +- example/httpMethods/package.mill | 2 +- example/minimalApplication/package.mill | 2 +- example/minimalApplication2/package.mill | 2 +- example/queryParams/package.mill | 2 +- example/redirectAbort/package.mill | 2 +- example/scalatags/package.mill | 2 +- example/staticFiles/package.mill | 2 +- example/staticFiles2/package.mill | 2 +- example/todo/package.mill | 2 +- example/todoApi/package.mill | 2 +- example/todoDb/package.mill | 2 +- example/twirl/package.mill | 2 +- example/variableRoutes/package.mill | 2 +- example/websockets/package.mill | 2 +- example/websockets2/package.mill | 2 +- example/websockets3/package.mill | 2 +- example/websockets4/package.mill | 2 +- 28 files changed, 33 insertions(+), 29 deletions(-) diff --git a/build.mill b/build.mill index 898385480f..95013993ad 100644 --- a/build.mill +++ b/build.mill @@ -50,7 +50,7 @@ trait CaskMainModule extends CaskModule { object test extends ScalaTests with TestModule.Utest{ def ivyDeps = Agg( ivy"com.lihaoyi::utest::0.8.4", - ivy"com.lihaoyi::requests::0.8.0" + ivy"com.lihaoyi::requests::0.9.0" ) } def moduleDeps = Seq(cask.util.jvm(crossScalaVersion)) diff --git a/cask/src/cask/decorators/compress.scala b/cask/src/cask/decorators/compress.scala index 3a28dd020f..cd384c1ad5 100644 --- a/cask/src/cask/decorators/compress.scala +++ b/cask/src/cask/decorators/compress.scala @@ -20,7 +20,9 @@ class compress extends cask.RawDecorator{ wrap.flush() wrap.close() } - override def headers = v.data.headers + // Since we don't know the length of the gzipped data ahead of time, + // we drop the content length header. + override def headers = v.data.headers.filter(_._1 != "Content-Length") } -> Seq("Content-Encoding" -> "gzip") }else if (acceptEncodings.exists(_.toLowerCase == "deflate")){ new Response.Data { @@ -29,7 +31,9 @@ class compress extends cask.RawDecorator{ v.data.write(wrap) wrap.flush() } - override def headers = v.data.headers + // Since we don't know the length of the compressed data ahead of + // time, we drop the content length header. + override def headers = v.data.headers.filter(_._1 != "Content-Length") } -> Seq("Content-Encoding" -> "deflate") }else v.data -> Nil Response( diff --git a/example/compress/package.mill b/example/compress/package.mill index 2de2f26b5a..9cccc5e677 100644 --- a/example/compress/package.mill +++ b/example/compress/package.mill @@ -12,7 +12,7 @@ trait AppModule extends CrossScalaModule{ def ivyDeps = Agg( ivy"com.lihaoyi::utest::0.8.4", - ivy"com.lihaoyi::requests::0.8.0", + ivy"com.lihaoyi::requests::0.9.0", ) } } diff --git a/example/compress2/package.mill b/example/compress2/package.mill index fa4b7a905c..c62df06bdc 100644 --- a/example/compress2/package.mill +++ b/example/compress2/package.mill @@ -12,7 +12,7 @@ trait AppModule extends CrossScalaModule{ def ivyDeps = Agg( ivy"com.lihaoyi::utest::0.8.4", - ivy"com.lihaoyi::requests::0.8.0", + ivy"com.lihaoyi::requests::0.9.0", ) } } diff --git a/example/compress3/package.mill b/example/compress3/package.mill index 0d02a23fd5..691ec66fed 100644 --- a/example/compress3/package.mill +++ b/example/compress3/package.mill @@ -12,7 +12,7 @@ trait AppModule extends CrossScalaModule{ def ivyDeps = Agg( ivy"com.lihaoyi::utest::0.8.4", - ivy"com.lihaoyi::requests::0.8.0", + ivy"com.lihaoyi::requests::0.9.0", ) } } diff --git a/example/cookies/package.mill b/example/cookies/package.mill index f248af91f1..8f481d11d9 100644 --- a/example/cookies/package.mill +++ b/example/cookies/package.mill @@ -12,7 +12,7 @@ trait AppModule extends CrossScalaModule{ def ivyDeps = Agg( ivy"com.lihaoyi::utest::0.8.4", - ivy"com.lihaoyi::requests::0.8.0", + ivy"com.lihaoyi::requests::0.9.0", ) } } diff --git a/example/decorated/package.mill b/example/decorated/package.mill index aa0875011e..5b2d0b176d 100644 --- a/example/decorated/package.mill +++ b/example/decorated/package.mill @@ -12,7 +12,7 @@ trait AppModule extends CrossScalaModule{ def ivyDeps = Agg( ivy"com.lihaoyi::utest::0.8.4", - ivy"com.lihaoyi::requests::0.8.0", + ivy"com.lihaoyi::requests::0.9.0", ) } } diff --git a/example/decorated2/package.mill b/example/decorated2/package.mill index 71f43443af..07adda85b1 100644 --- a/example/decorated2/package.mill +++ b/example/decorated2/package.mill @@ -12,7 +12,7 @@ trait AppModule extends CrossScalaModule{ def ivyDeps = Agg( ivy"com.lihaoyi::utest::0.8.4", - ivy"com.lihaoyi::requests::0.8.0", + ivy"com.lihaoyi::requests::0.9.0", ) } } diff --git a/example/decoratedContext/package.mill b/example/decoratedContext/package.mill index 7534fd91f2..52adf69ae8 100644 --- a/example/decoratedContext/package.mill +++ b/example/decoratedContext/package.mill @@ -13,7 +13,7 @@ object app extends ScalaModule{ def ivyDeps = Agg( ivy"com.lihaoyi::utest::0.8.4", - ivy"com.lihaoyi::requests::0.8.0", + ivy"com.lihaoyi::requests::0.9.0", ) } } diff --git a/example/endpoints/package.mill b/example/endpoints/package.mill index 89837035c7..9a4bd3071f 100644 --- a/example/endpoints/package.mill +++ b/example/endpoints/package.mill @@ -12,7 +12,7 @@ trait AppModule extends CrossScalaModule{ def ivyDeps = Agg( ivy"com.lihaoyi::utest::0.8.4", - ivy"com.lihaoyi::requests::0.8.0", + ivy"com.lihaoyi::requests::0.9.0", ) } } diff --git a/example/formJsonPost/package.mill b/example/formJsonPost/package.mill index ca5b713f9c..2a4099fa2e 100644 --- a/example/formJsonPost/package.mill +++ b/example/formJsonPost/package.mill @@ -12,7 +12,7 @@ trait AppModule extends CrossScalaModule{ def ivyDeps = Agg( ivy"com.lihaoyi::utest::0.8.4", - ivy"com.lihaoyi::requests::0.8.0" + ivy"com.lihaoyi::requests::0.9.0" ) } } diff --git a/example/httpMethods/package.mill b/example/httpMethods/package.mill index 25fea79b2d..222e9b9b52 100644 --- a/example/httpMethods/package.mill +++ b/example/httpMethods/package.mill @@ -12,7 +12,7 @@ trait AppModule extends CrossScalaModule{ def ivyDeps = Agg( ivy"com.lihaoyi::utest::0.8.4", - ivy"com.lihaoyi::requests::0.8.0", + ivy"com.lihaoyi::requests::0.9.0", ) def forkArgs = Seq("--add-opens=java.base/java.net=ALL-UNNAMED") } diff --git a/example/minimalApplication/package.mill b/example/minimalApplication/package.mill index 4c12f4da76..e4fe2ffd75 100644 --- a/example/minimalApplication/package.mill +++ b/example/minimalApplication/package.mill @@ -12,7 +12,7 @@ trait AppModule extends CrossScalaModule{ def ivyDeps = Agg( ivy"com.lihaoyi::utest::0.8.4", - ivy"com.lihaoyi::requests::0.8.0", + ivy"com.lihaoyi::requests::0.9.0", ) } } diff --git a/example/minimalApplication2/package.mill b/example/minimalApplication2/package.mill index ffb542135a..9ff8cdbce2 100644 --- a/example/minimalApplication2/package.mill +++ b/example/minimalApplication2/package.mill @@ -12,7 +12,7 @@ trait AppModule extends CrossScalaModule{ def ivyDeps = Agg( ivy"com.lihaoyi::utest::0.8.4", - ivy"com.lihaoyi::requests::0.8.0", + ivy"com.lihaoyi::requests::0.9.0", ) } } diff --git a/example/queryParams/package.mill b/example/queryParams/package.mill index 9e19312405..511929aa2b 100644 --- a/example/queryParams/package.mill +++ b/example/queryParams/package.mill @@ -12,7 +12,7 @@ trait AppModule extends CrossScalaModule{ def ivyDeps = Agg( ivy"com.lihaoyi::utest::0.8.4", - ivy"com.lihaoyi::requests::0.8.0", + ivy"com.lihaoyi::requests::0.9.0", ) } } diff --git a/example/redirectAbort/package.mill b/example/redirectAbort/package.mill index e6d91293ac..e5e33349a3 100644 --- a/example/redirectAbort/package.mill +++ b/example/redirectAbort/package.mill @@ -12,7 +12,7 @@ trait AppModule extends CrossScalaModule{ def ivyDeps = Agg( ivy"com.lihaoyi::utest::0.8.4", - ivy"com.lihaoyi::requests::0.8.0", + ivy"com.lihaoyi::requests::0.9.0", ) } } diff --git a/example/scalatags/package.mill b/example/scalatags/package.mill index f73590643a..d78006028d 100644 --- a/example/scalatags/package.mill +++ b/example/scalatags/package.mill @@ -14,7 +14,7 @@ trait AppModule extends CrossScalaModule{ def ivyDeps = Agg( ivy"com.lihaoyi::utest::0.8.4", - ivy"com.lihaoyi::requests::0.8.0", + ivy"com.lihaoyi::requests::0.9.0", ) } } diff --git a/example/staticFiles/package.mill b/example/staticFiles/package.mill index 0e52852a0d..003685dc15 100644 --- a/example/staticFiles/package.mill +++ b/example/staticFiles/package.mill @@ -13,7 +13,7 @@ trait AppModule extends CrossScalaModule{ app => def ivyDeps = Agg( ivy"com.lihaoyi::utest::0.8.4", - ivy"com.lihaoyi::requests::0.8.0", + ivy"com.lihaoyi::requests::0.9.0", ) def forkWorkingDir = app.millSourcePath diff --git a/example/staticFiles2/package.mill b/example/staticFiles2/package.mill index 8e62b139ac..27881395e7 100644 --- a/example/staticFiles2/package.mill +++ b/example/staticFiles2/package.mill @@ -13,7 +13,7 @@ trait AppModule extends CrossScalaModule{ app => def ivyDeps = Agg( ivy"com.lihaoyi::utest::0.8.4", - ivy"com.lihaoyi::requests::0.8.0", + ivy"com.lihaoyi::requests::0.9.0", ) def forkWorkingDir = app.millSourcePath diff --git a/example/todo/package.mill b/example/todo/package.mill index 67f563b792..135ea7469a 100644 --- a/example/todo/package.mill +++ b/example/todo/package.mill @@ -17,7 +17,7 @@ trait AppModule extends CrossScalaModule{ def ivyDeps = Agg( ivy"com.lihaoyi::utest::0.8.4", - ivy"com.lihaoyi::requests::0.8.0", + ivy"com.lihaoyi::requests::0.9.0", ) } } diff --git a/example/todoApi/package.mill b/example/todoApi/package.mill index 2fa9d195df..b37733de4b 100644 --- a/example/todoApi/package.mill +++ b/example/todoApi/package.mill @@ -12,7 +12,7 @@ trait AppModule extends CrossScalaModule{ def ivyDeps = Agg( ivy"com.lihaoyi::utest::0.8.4", - ivy"com.lihaoyi::requests::0.8.0", + ivy"com.lihaoyi::requests::0.9.0", ) } } diff --git a/example/todoDb/package.mill b/example/todoDb/package.mill index 2c38d2b0d5..0e0b242741 100644 --- a/example/todoDb/package.mill +++ b/example/todoDb/package.mill @@ -15,7 +15,7 @@ trait AppModule extends CrossScalaModule{ def ivyDeps = Agg( ivy"com.lihaoyi::utest::0.8.4", - ivy"com.lihaoyi::requests::0.8.0", + ivy"com.lihaoyi::requests::0.9.0", ) } } diff --git a/example/twirl/package.mill b/example/twirl/package.mill index aff2e71665..9769cf1b99 100644 --- a/example/twirl/package.mill +++ b/example/twirl/package.mill @@ -19,7 +19,7 @@ trait AppModule extends CrossScalaModule with mill.twirllib.TwirlModule{ def ivyDeps = Agg( ivy"com.lihaoyi::utest::0.8.4", - ivy"com.lihaoyi::requests::0.8.0", + ivy"com.lihaoyi::requests::0.9.0", ) } } diff --git a/example/variableRoutes/package.mill b/example/variableRoutes/package.mill index c0723c276f..275b17f52c 100644 --- a/example/variableRoutes/package.mill +++ b/example/variableRoutes/package.mill @@ -12,7 +12,7 @@ trait AppModule extends CrossScalaModule{ def ivyDeps = Agg( ivy"com.lihaoyi::utest::0.8.4", - ivy"com.lihaoyi::requests::0.8.0", + ivy"com.lihaoyi::requests::0.9.0", ) } } diff --git a/example/websockets/package.mill b/example/websockets/package.mill index a79c33168b..a62ac76397 100644 --- a/example/websockets/package.mill +++ b/example/websockets/package.mill @@ -12,7 +12,7 @@ trait AppModule extends CrossScalaModule{ def ivyDeps = Agg( ivy"com.lihaoyi::utest::0.8.4", - ivy"com.lihaoyi::requests::0.8.0", + ivy"com.lihaoyi::requests::0.9.0", ivy"org.asynchttpclient:async-http-client:2.12.3" ) } diff --git a/example/websockets2/package.mill b/example/websockets2/package.mill index 4441b5ebb2..5b16b50ce3 100644 --- a/example/websockets2/package.mill +++ b/example/websockets2/package.mill @@ -12,7 +12,7 @@ trait AppModule extends CrossScalaModule{ def ivyDeps = Agg( ivy"com.lihaoyi::utest::0.8.4", - ivy"com.lihaoyi::requests::0.8.0", + ivy"com.lihaoyi::requests::0.9.0", ivy"org.asynchttpclient:async-http-client:2.12.3" ) } diff --git a/example/websockets3/package.mill b/example/websockets3/package.mill index 52b4f2a9c2..e61015bc9a 100644 --- a/example/websockets3/package.mill +++ b/example/websockets3/package.mill @@ -12,7 +12,7 @@ trait AppModule extends CrossScalaModule{ def ivyDeps = Agg( ivy"com.lihaoyi::utest::0.8.4", - ivy"com.lihaoyi::requests::0.8.0", + ivy"com.lihaoyi::requests::0.9.0", ivy"org.asynchttpclient:async-http-client:2.12.3" ) } diff --git a/example/websockets4/package.mill b/example/websockets4/package.mill index 801aef3e95..a4899689c8 100644 --- a/example/websockets4/package.mill +++ b/example/websockets4/package.mill @@ -12,7 +12,7 @@ trait AppModule extends CrossScalaModule{ def ivyDeps = Agg( ivy"com.lihaoyi::utest::0.8.4", - ivy"com.lihaoyi::requests::0.8.0", + ivy"com.lihaoyi::requests::0.9.0", ivy"org.asynchttpclient:async-http-client:2.12.3" ) }