Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions src/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,18 @@ describe("TypeIs#request(req)", () => {
});
});

describe("when Content-Type is application/xml or text/xml", () => {
it('should match "xml" for application/xml', () => {
const req = createRequest("application/xml");
assert.strictEqual(new TypeIs(["xml"]).request(req), "application/xml");
});

it('should match "xml" for text/xml', () => {
const req = createRequest("text/xml");
assert.strictEqual(new TypeIs(["xml"]).request(req), "text/xml");
});
});

describe("when Content-Type: application/x-www-form-urlencoded", () => {
it('should match "urlencoded"', () => {
const req = createRequest("application/x-www-form-urlencoded");
Expand Down Expand Up @@ -504,6 +516,19 @@ describe("TypeIs#is(value)", () => {
});
});

describe("when media type is application/xml or text/xml", () => {
it('should match "xml" for application/xml', () => {
assert.strictEqual(
new TypeIs(["xml"]).is("application/xml"),
"application/xml",
);
});

it('should match "xml" for text/xml', () => {
assert.strictEqual(new TypeIs(["xml"]).is("text/xml"), "text/xml");
});
});

describe("when media type is application/x-www-form-urlencoded", () => {
it('should match "urlencoded"', () => {
assert.strictEqual(
Expand Down Expand Up @@ -639,6 +664,10 @@ describe("normalize(type)", () => {
it('should expand special "multipart"', () => {
assert.strictEqual(normalize("multipart"), "multipart/*");
});

it('should expand special "xml"', () => {
assert.deepStrictEqual(normalize("xml"), ["application/xml", "text/xml"]);
});
});

function createRequest(type?: string) {
Expand Down
2 changes: 2 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ export function DEFAULT_LOOKUP(value: string): string | string[] | undefined {
return "multipart/*";
case "json":
return "application/json";
case "xml":
return ["application/xml", "text/xml"];
default:
return undefined;
}
Expand Down