Skip to content

Commit

Permalink
Minor cleanup for Undertow exchange errors
Browse files Browse the repository at this point in the history
  • Loading branch information
darkfrog26 committed Jun 5, 2024
1 parent 6713ab5 commit d2a5e37
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 14 deletions.
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name := "spice"
ThisBuild / organization := "com.outr"
ThisBuild / version := "0.5.9"
ThisBuild / version := "0.5.10-SNAPSHOT"

val scala213: String = "2.13.14"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,15 @@ object UndertowRequestParser {
}
Some(FormDataContent(data.toMap))
case ct =>
val stream = fs2.io.readInputStream[IO](
fis = IO(new ChannelInputStream(exchange.getRequestChannel)),
chunkSize = 1024
)
Some(StreamContent(stream, ct))
Option(exchange.getRequestChannel) match {
case Some(channel) =>
val stream = fs2.io.readInputStream[IO](
fis = IO(new ChannelInputStream(channel)),
chunkSize = 1024
)
Some(StreamContent(stream, ct))
case None => throw new NullPointerException(s"Channel is null for request channel. Probably already consumed.")
}
}
} else {
None
Expand Down
18 changes: 10 additions & 8 deletions server/src/main/scala/spice/http/server/rest/Restful.scala
Original file line number Diff line number Diff line change
Expand Up @@ -212,14 +212,16 @@ object Restful {
Obj(jsonValues ++ fileValues)
}
case _ =>
content.asString.map { contentString =>
val firstChar = contentString.charAt(0)
val json = if (Set('"', '{', '[').contains(firstChar)) {
JsonParser(contentString)
} else {
Str(contentString)
}
json
content.asString.map {
case "" => obj()
case contentString =>
val firstChar = contentString.charAt(0)
val json = if (Set('"', '{', '[').contains(firstChar)) {
JsonParser(contentString)
} else {
Str(contentString)
}
json
}
}

Expand Down

0 comments on commit d2a5e37

Please sign in to comment.