Skip to content

Commit b8f4f29

Browse files
committed
Add /xml httpbin-compatible endpoint
1 parent eaa348f commit b8f4f29

2 files changed

Lines changed: 41 additions & 0 deletions

File tree

src/endpoints/http-index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ export * from './http/delay.js';
3232
export * from './http/cookies.js'
3333
export * from './http/basic-auth.js';
3434
export * from './http/json.js';
35+
export * from './http/xml.js';
3536
export * from './http/trailers.js';
3637
export * from './http/error/close.js';
3738
export * from './http/error/reset.js';

src/endpoints/http/xml.ts

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import { HttpEndpoint, HttpHandler } from '../http-index.js';
2+
3+
const matchPath = (path: string) => path === '/xml';
4+
5+
const handle: HttpHandler = (req, res) => {
6+
res.writeHead(200, {
7+
'content-type': 'application/xml'
8+
});
9+
10+
// HTTPBin seems to just return this fixed example document:
11+
res.end(`<?xml version='1.0' encoding='us-ascii'?>
12+
13+
<!-- A SAMPLE set of slides -->
14+
15+
<slideshow
16+
title="Sample Slide Show"
17+
date="Date of publication"
18+
author="Yours Truly"
19+
>
20+
21+
<!-- TITLE SLIDE -->
22+
<slide type="all">
23+
<title>Wake up to WonderWidgets!</title>
24+
</slide>
25+
26+
<!-- OVERVIEW -->
27+
<slide type="all">
28+
<title>Overview</title>
29+
<item>Why <em>WonderWidgets</em> are great</item>
30+
<item/>
31+
<item>Who <em>buys</em> WonderWidgets</item>
32+
</slide>
33+
34+
</slideshow>`);
35+
}
36+
37+
export const xml: HttpEndpoint = {
38+
matchPath,
39+
handle
40+
};

0 commit comments

Comments
 (0)