Skip to content

Commit

Permalink
KTOR-7278: review points fix
Browse files Browse the repository at this point in the history
  • Loading branch information
anton-erofeev committed Nov 5, 2024
1 parent 42bddad commit bb9772a
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 7 deletions.
3 changes: 2 additions & 1 deletion ktor-http/common/src/io/ktor/http/ContentTypes.kt
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ public class ContentType private constructor(
* Checks if `this` type matches a [pattern] type taking into account placeholder symbols `*` and parameters.
*/
public fun match(pattern: ContentType): Boolean {
if (pattern.contentType != "*" && !pattern.contentType.equals(contentType, ignoreCase = true)) {
if (pattern.contentType != "*" && contentType != "*"
&& !pattern.contentType.equals(contentType, ignoreCase = true)) {
return false
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,24 +193,63 @@ class RoutingProcessingTest {

@Test
fun testRoutingAcceptContentSubtypeWildcard() = testApplication {

routing {
route("getImage") {
route("image") {
accept(ContentType.Image.Any) {
get { call.respondText { "Image" } }
}
}
route("any") {
accept(ContentType.Any) {
get { call.respondText { "Any" } }
}
}
}

on("making request to /getImage with Accept image/png") {
client.get("/getImage") {
header(HttpHeaders.Accept, "image/png")
on("making request to /image with Accept image/png") {
client.get("/image") {
header(HttpHeaders.Accept, ContentType.Image.PNG)
}.let {
assertEquals(HttpStatusCode.OK, it.status)
assertEquals("Image", it.bodyAsText())
}
.let {
}

on("making request to /image with Accept */*") {
client.get("/image") {
header(HttpHeaders.Accept, ContentType.Any)
}.let {
assertEquals(HttpStatusCode.OK, it.status)
assertEquals("Image", it.bodyAsText())
}
}

on("making request to /any with Accept image/png") {
client.get("/any") {
header(HttpHeaders.Accept, ContentType.Image.PNG)
}.let {
assertEquals(HttpStatusCode.OK, it.status)
assertEquals("Any", it.bodyAsText())
}
}

on("making request to /any with Accept image/*") {
client.get("/any") {
header(HttpHeaders.Accept, ContentType.Image.Any)
}.let {
assertEquals(HttpStatusCode.OK, it.status)
assertEquals("Any", it.bodyAsText())
}
}

on("making request to /any with Accept */*") {
client.get("/any") {
header(HttpHeaders.Accept, ContentType.Any)
}.let {
assertEquals(HttpStatusCode.OK, it.status)
assertEquals("Any", it.bodyAsText())
}
}
}

@Test
Expand Down

0 comments on commit bb9772a

Please sign in to comment.