Skip to content

Commit 4bf428c

Browse files
committed
feat: add content type matcher
This matcher validates the body by content type only, typically through the magic bytes. Signed-off-by: JP-Ellis <josh@jpellis.me>
1 parent 98d1c19 commit 4bf428c

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

src/pact/match/__init__.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -968,6 +968,24 @@ def type(
968968
return GenericMatcher("type", value, min=min, max=max, generator=generator)
969969

970970

971+
def content_type(content_type: builtins.str) -> AbstractMatcher[Any]:
972+
"""
973+
Match a value by content type.
974+
975+
Unlike other matchers, this matcher does not take a `value` argument, as it
976+
is typically used to match binary data (e.g., images, files) where the
977+
actual content is impractical to specify.
978+
979+
Args:
980+
content_type:
981+
Content type to match (e.g., "image/jpeg", "application/pdf").
982+
983+
Returns:
984+
Matcher for the given content type.
985+
"""
986+
return GenericMatcher("contentType", value=content_type)
987+
988+
971989
def like(
972990
value: _T,
973991
/,

0 commit comments

Comments
 (0)