Skip to content

Commit 95a793f

Browse files
fix include support for priority/weight
1 parent 1cf2624 commit 95a793f

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

packages/http/src/IsRequest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ public function accepts(ContentType ...$contentTypes): bool
154154

155155
$mediaTypes[] = [
156156
'mediaType' => $acceptedType->before('/')->toString(),
157-
'subType' => $acceptedType->afterFirst('/')->toString(),
157+
'subType' => $acceptedType->afterFirst('/')->beforeLast(';q')->toString(),
158158
];
159159
}
160160

packages/http/tests/GenericRequestTest.php

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,21 @@ public function test_accepts_with_wildcard_subtype(): void
150150
$this->assertTrue($request->accepts(ContentType::XML));
151151
}
152152

153-
public function test_accepts_can_take_multiple_params(): void
153+
public function test_accepts_can_handle_priorities(): void
154+
{
155+
$request = new GenericRequest(
156+
method: Method::GET,
157+
uri: '/',
158+
headers: [
159+
'Accept' => 'text/html, application/xhtml+xml;q=0.8, application/xml;q=0.8, image/webp',
160+
],
161+
);
162+
163+
$this->assertTrue($request->accepts(ContentType::XHTML));
164+
$this->assertTrue($request->accepts(ContentType::XML));
165+
}
166+
167+
public function test_accepts_returns_true_on_first_match(): void
154168
{
155169
$request = new GenericRequest(
156170
method: Method::GET,

0 commit comments

Comments
 (0)