Skip to content

Commit

Permalink
Drop content-length header in compressed decorator (#148)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
jodersky authored Nov 3, 2024
1 parent 2e98bba commit 98aa493
Show file tree
Hide file tree
Showing 28 changed files with 33 additions and 29 deletions.
2 changes: 1 addition & 1 deletion build.mill
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
8 changes: 6 additions & 2 deletions cask/src/cask/decorators/compress.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion example/compress/package.mill
Original file line number Diff line number Diff line change
Expand Up @@ -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",
)
}
}
2 changes: 1 addition & 1 deletion example/compress2/package.mill
Original file line number Diff line number Diff line change
Expand Up @@ -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",
)
}
}
2 changes: 1 addition & 1 deletion example/compress3/package.mill
Original file line number Diff line number Diff line change
Expand Up @@ -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",
)
}
}
2 changes: 1 addition & 1 deletion example/cookies/package.mill
Original file line number Diff line number Diff line change
Expand Up @@ -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",
)
}
}
2 changes: 1 addition & 1 deletion example/decorated/package.mill
Original file line number Diff line number Diff line change
Expand Up @@ -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",
)
}
}
2 changes: 1 addition & 1 deletion example/decorated2/package.mill
Original file line number Diff line number Diff line change
Expand Up @@ -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",
)
}
}
2 changes: 1 addition & 1 deletion example/decoratedContext/package.mill
Original file line number Diff line number Diff line change
Expand Up @@ -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",
)
}
}
2 changes: 1 addition & 1 deletion example/endpoints/package.mill
Original file line number Diff line number Diff line change
Expand Up @@ -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",
)
}
}
2 changes: 1 addition & 1 deletion example/formJsonPost/package.mill
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
}
}
2 changes: 1 addition & 1 deletion example/httpMethods/package.mill
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand Down
2 changes: 1 addition & 1 deletion example/minimalApplication/package.mill
Original file line number Diff line number Diff line change
Expand Up @@ -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",
)
}
}
2 changes: 1 addition & 1 deletion example/minimalApplication2/package.mill
Original file line number Diff line number Diff line change
Expand Up @@ -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",
)
}
}
2 changes: 1 addition & 1 deletion example/queryParams/package.mill
Original file line number Diff line number Diff line change
Expand Up @@ -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",
)
}
}
2 changes: 1 addition & 1 deletion example/redirectAbort/package.mill
Original file line number Diff line number Diff line change
Expand Up @@ -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",
)
}
}
2 changes: 1 addition & 1 deletion example/scalatags/package.mill
Original file line number Diff line number Diff line change
Expand Up @@ -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",
)
}
}
2 changes: 1 addition & 1 deletion example/staticFiles/package.mill
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion example/staticFiles2/package.mill
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion example/todo/package.mill
Original file line number Diff line number Diff line change
Expand Up @@ -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",
)
}
}
2 changes: 1 addition & 1 deletion example/todoApi/package.mill
Original file line number Diff line number Diff line change
Expand Up @@ -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",
)
}
}
2 changes: 1 addition & 1 deletion example/todoDb/package.mill
Original file line number Diff line number Diff line change
Expand Up @@ -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",
)
}
}
2 changes: 1 addition & 1 deletion example/twirl/package.mill
Original file line number Diff line number Diff line change
Expand Up @@ -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",
)
}
}
2 changes: 1 addition & 1 deletion example/variableRoutes/package.mill
Original file line number Diff line number Diff line change
Expand Up @@ -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",
)
}
}
2 changes: 1 addition & 1 deletion example/websockets/package.mill
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
}
Expand Down
2 changes: 1 addition & 1 deletion example/websockets2/package.mill
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
}
Expand Down
2 changes: 1 addition & 1 deletion example/websockets3/package.mill
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
}
Expand Down
2 changes: 1 addition & 1 deletion example/websockets4/package.mill
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
}
Expand Down

0 comments on commit 98aa493

Please sign in to comment.