diff --git a/src/index.spec.ts b/src/index.spec.ts index 6ce6073..5132e5f 100644 --- a/src/index.spec.ts +++ b/src/index.spec.ts @@ -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"); @@ -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( @@ -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) { diff --git a/src/index.ts b/src/index.ts index aa3f4af..3730152 100644 --- a/src/index.ts +++ b/src/index.ts @@ -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; }