-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathecho.html
More file actions
773 lines (726 loc) · 46 KB
/
echo.html
File metadata and controls
773 lines (726 loc) · 46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
<!DOCTYPE html>
<!-- @su:responder-script
// =============================================================================
// RESPONDER SCRIPT - paired with echo.html, auto-deployed to the responder's
// `script` setting by dev/tools/deploy.ts. This HTML comment is stripped from
// the served body by html-minifier-terser (`removeComments: true`).
// See dev/tools/AGENTS.md → "Responder Script (`@su:responder-script`)".
//
// Wire format (after base64url-decode):
// | 4 bytes ulen (LE u32) | N bytes raw-deflate(JSON.stringify(state)) |
// =============================================================================
(() => {
const encoded = context.query.c;
if (!encoded) {
// No config - fall through to the default body (the configurator HTML).
return null;
}
// Pure-JS base64url decoder (no atob in the Deno sandbox).
const fromBase64Url = (input) => {
const C = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
const stripped = input.replace(/-/g, '+').replace(/_/g, '/').replace(/=+$/, '');
const out = [];
for (let i = 0; i < stripped.length; i += 4) {
const a = C.indexOf(stripped[i]);
const b = C.indexOf(stripped[i + 1]);
const c = C.indexOf(stripped[i + 2]);
const d = C.indexOf(stripped[i + 3]);
out.push((a << 2) | (b >> 4));
if (c >= 0) out.push(((b & 15) << 4) | (c >> 2));
if (d >= 0) out.push(((c & 3) << 6) | d);
}
return new Uint8Array(out);
};
// ----------------------------------------------------------------------
// Vendored: tiny-inflate@1.0.3 (Devon Govett, MIT) - pure-JS raw DEFLATE
// inflater (~1 KB minified). Source: https://github.com/foliojs/tiny-inflate
// The Deno sandbox has no DecompressionStream so we ship our own.
//
// Local hardening: tiny-inflate does not bounds-check the source stream, so
// adversarial input (e.g. a hand-typed ?c=) can spin in an infinite loop
// reading undefined bytes. The Data ctor below throws as soon as the source
// pointer runs past `source.length + 4` (small slack for the bit buffer's
// 24-bit refill window), turning hangs into a clean catch-able 'Data error'.
// ----------------------------------------------------------------------
const tinf_uncompress = (() => {
const TINF_OK = 0, TINF_DATA_ERROR = -3;
function Tree() { this.table = new Uint16Array(16); this.trans = new Uint16Array(288); }
function Data(source, dest) {
this.tag = 0; this.bitcount = 0;
this.dest = dest; this.destLen = 0;
this.ltree = new Tree(); this.dtree = new Tree();
// Bounds-checking source proxy: every out-of-range read throws.
this.source = source;
const max = source.length;
let idx = 0;
Object.defineProperty(this, 'sourceIndex', {
get() { return idx; },
set(v) {
if (v > max + 4) throw new Error('Data error');
idx = v;
},
});
}
const sltree = new Tree(), sdtree = new Tree();
const length_bits = new Uint8Array(30), length_base = new Uint16Array(30);
const dist_bits = new Uint8Array(30), dist_base = new Uint16Array(30);
const clcidx = new Uint8Array([16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15]);
const code_tree = new Tree();
const lengths = new Uint8Array(288 + 32);
const offs = new Uint16Array(16);
const buildBitsBase = (bits, base, delta, first) => {
let i, sum;
for (i = 0; i < delta; ++i) bits[i] = 0;
for (i = 0; i < 30 - delta; ++i) bits[i + delta] = i / delta | 0;
for (sum = first, i = 0; i < 30; ++i) { base[i] = sum; sum += 1 << bits[i]; }
};
const buildFixedTrees = (lt, dt) => {
let i;
for (i = 0; i < 7; ++i) lt.table[i] = 0;
lt.table[7] = 24; lt.table[8] = 152; lt.table[9] = 112;
for (i = 0; i < 24; ++i) lt.trans[i] = 256 + i;
for (i = 0; i < 144; ++i) lt.trans[24 + i] = i;
for (i = 0; i < 8; ++i) lt.trans[24 + 144 + i] = 280 + i;
for (i = 0; i < 112; ++i) lt.trans[24 + 144 + 8 + i] = 144 + i;
for (i = 0; i < 5; ++i) dt.table[i] = 0;
dt.table[5] = 32;
for (i = 0; i < 32; ++i) dt.trans[i] = i;
};
const buildTree = (t, lengths, off, num) => {
let i, sum;
for (i = 0; i < 16; ++i) t.table[i] = 0;
for (i = 0; i < num; ++i) t.table[lengths[off + i]]++;
t.table[0] = 0;
for (sum = 0, i = 0; i < 16; ++i) { offs[i] = sum; sum += t.table[i]; }
for (i = 0; i < num; ++i) { if (lengths[off + i]) t.trans[offs[lengths[off + i]]++] = i; }
};
const getbit = (d) => {
if (!d.bitcount--) { d.tag = d.source[d.sourceIndex++]; d.bitcount = 7; }
const bit = d.tag & 1; d.tag >>>= 1; return bit;
};
const readBits = (d, num, base) => {
if (!num) return base;
while (d.bitcount < 24) { d.tag |= d.source[d.sourceIndex++] << d.bitcount; d.bitcount += 8; }
const val = d.tag & (0xffff >>> (16 - num));
d.tag >>>= num; d.bitcount -= num; return val + base;
};
const decodeSymbol = (d, t) => {
while (d.bitcount < 24) { d.tag |= d.source[d.sourceIndex++] << d.bitcount; d.bitcount += 8; }
let sum = 0, cur = 0, len = 0; let tag = d.tag;
do {
cur = 2 * cur + (tag & 1); tag >>>= 1; ++len;
sum += t.table[len]; cur -= t.table[len];
} while (cur >= 0);
d.tag = tag; d.bitcount -= len;
return t.trans[sum + cur];
};
const decodeTrees = (d, lt, dt) => {
const hlit = readBits(d, 5, 257);
const hdist = readBits(d, 5, 1);
const hclen = readBits(d, 4, 4);
let i, num, length;
for (i = 0; i < 19; ++i) lengths[i] = 0;
for (i = 0; i < hclen; ++i) { const clen = readBits(d, 3, 0); lengths[clcidx[i]] = clen; }
buildTree(code_tree, lengths, 0, 19);
for (num = 0; num < hlit + hdist;) {
const sym = decodeSymbol(d, code_tree);
switch (sym) {
case 16: { const prev = lengths[num - 1]; for (length = readBits(d, 2, 3); length; --length) lengths[num++] = prev; break; }
case 17: for (length = readBits(d, 3, 3); length; --length) lengths[num++] = 0; break;
case 18: for (length = readBits(d, 7, 11); length; --length) lengths[num++] = 0; break;
default: lengths[num++] = sym; break;
}
}
buildTree(lt, lengths, 0, hlit);
buildTree(dt, lengths, hlit, hdist);
};
const inflateBlockData = (d, lt, dt) => {
while (1) {
let sym = decodeSymbol(d, lt);
if (sym === 256) return TINF_OK;
if (sym < 256) { d.dest[d.destLen++] = sym; }
else {
let length, dist, offs2, i;
sym -= 257;
length = readBits(d, length_bits[sym], length_base[sym]);
dist = decodeSymbol(d, dt);
offs2 = d.destLen - readBits(d, dist_bits[dist], dist_base[dist]);
for (i = offs2; i < offs2 + length; ++i) d.dest[d.destLen++] = d.dest[i];
}
}
};
const inflateUncompressedBlock = (d) => {
let length, invlength, i;
while (d.bitcount > 8) { d.sourceIndex--; d.bitcount -= 8; }
length = d.source[d.sourceIndex + 1]; length = 256 * length + d.source[d.sourceIndex];
invlength = d.source[d.sourceIndex + 3]; invlength = 256 * invlength + d.source[d.sourceIndex + 2];
if (length !== (~invlength & 0x0000ffff)) return TINF_DATA_ERROR;
d.sourceIndex += 4;
for (i = length; i; --i) d.dest[d.destLen++] = d.source[d.sourceIndex++];
d.bitcount = 0;
return TINF_OK;
};
buildFixedTrees(sltree, sdtree);
buildBitsBase(length_bits, length_base, 4, 3);
buildBitsBase(dist_bits, dist_base, 2, 1);
length_bits[28] = 0; length_base[28] = 258;
return (source, dest) => {
const d = new Data(source, dest);
let bfinal, btype, res;
do {
bfinal = getbit(d);
btype = readBits(d, 2, 0);
switch (btype) {
case 0: res = inflateUncompressedBlock(d); break;
case 1: res = inflateBlockData(d, sltree, sdtree); break;
case 2: decodeTrees(d, d.ltree, d.dtree); res = inflateBlockData(d, d.ltree, d.dtree); break;
default: res = TINF_DATA_ERROR;
}
if (res !== TINF_OK) throw new Error('Data error');
} while (!bfinal);
return d.destLen < d.dest.length ? d.dest.subarray(0, d.destLen) : d.dest;
};
})();
try {
const bytes = fromBase64Url(encoded);
if (bytes.length < 4) throw new Error('payload too small');
const ulen = (bytes[0] | (bytes[1] << 8) | (bytes[2] << 16) | (bytes[3] << 24)) >>> 0;
// Defensive caps: reject obviously bogus headers before allocating or inflating.
// 1 MiB inflated is far beyond any plausible mock-response config.
if (ulen === 0 || ulen > 1 << 20) throw new Error('payload too large');
const inflated = new Uint8Array(ulen);
tinf_uncompress(bytes.subarray(4), inflated);
const cfg = JSON.parse(Deno.core.decode(inflated));
const headers = {};
for (const pair of (Array.isArray(cfg.h) ? cfg.h : [])) {
if (Array.isArray(pair) && pair[0]) {
headers[String(pair[0])] = String(pair[1] ?? '');
}
}
if (!Object.keys(headers).some((h) => h.toLowerCase() === 'content-type')) {
headers['Content-Type'] = 'text/plain; charset=utf-8';
}
return {
statusCode: Number.isInteger(cfg.s) ? cfg.s : 200,
headers,
body: typeof cfg.b === 'string' ? cfg.b : '',
};
} catch (e) {
return {
statusCode: 400,
headers: { 'Content-Type': 'text/plain; charset=utf-8' },
body: 'Invalid configuration in ?c=: ' + (e.message || String(e)),
};
}
})();
-->
<html lang="en" data-theme="dark">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>HTTP Echo and Mock Response Builder | Secutils.dev</title>
<meta name="description" content="Free HTTP echo and mock response builder. Configure status code, headers, and body, then serve as a shareable URL. Browser-only, state in URL, no signup.">
<meta name="robots" content="index, follow, max-image-preview:large">
<link rel="canonical" href="https://{{TOOLS_HOST}}/echo">
<meta name="su-tool-path" content="/echo">
<meta name="su-tool-name" content="HTTP Echo / Mock Response">
<meta name="su-tool-description" content="Build a fully customizable mock HTTP response (status, headers, body) and serve it as a shareable URL. State in URL, no signup.">
<meta name="su-tool-promote" content="true">
<meta property="og:type" content="website">
<meta property="og:site_name" content="Secutils.dev">
<meta property="og:title" content="HTTP Echo & Mock Response Builder">
<meta property="og:description" content="Free HTTP echo and mock response builder. Configure status code, headers, and body. Serve as a shareable URL. Browser-only.">
<meta property="og:url" content="https://{{TOOLS_HOST}}/echo">
<meta property="og:image" content="https://secutils.dev/docs/img/og/og-echo.png">
<meta property="og:image:width" content="1200">
<meta property="og:image:height" content="630">
<meta property="og:image:alt" content="HTTP Echo / Mock Response Builder on Secutils.dev.">
<meta property="og:locale" content="en_US">
<meta name="twitter:card" content="summary_large_image">
<meta name="twitter:title" content="HTTP Echo & Mock Response Builder">
<meta name="twitter:description" content="Free HTTP echo and mock response builder. Configure status, headers, body. Serve as a shareable URL. No signup.">
<meta name="twitter:image" content="https://secutils.dev/docs/img/og/og-echo.png">
<script type="application/ld+json">{"@context":"https://schema.org","@type":"WebApplication","name":"HTTP Echo / Mock Response","url":"https://{{TOOLS_HOST}}/echo","applicationCategory":"DeveloperApplication","operatingSystem":"Any","browserRequirements":"Requires JavaScript","isAccessibleForFree":true,"offers":{"@type":"Offer","price":"0","priceCurrency":"USD"},"publisher":{"@type":"Organization","name":"Secutils.dev","url":"https://secutils.dev"},"sameAs":"https://github.com/secutils-dev/secutils/blob/main/dev/tools/echo.html","description":"Free HTTP echo and mock response builder. Configure status code, headers, and body, then serve as a shareable URL. Browser-only, state in URL, no signup."}</script>
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@300..700&family=Roboto+Mono:wght@400..700&display=swap" rel="stylesheet">
<!-- Privacy-friendly analytics by Plausible -->
<script defer src="https://tools.secutils.dev/js/script.js"></script>
<script>
window.plausible = window.plausible || function () { (plausible.q = plausible.q || []).push(arguments) };
plausible.init = plausible.init || function (i) { plausible.o = i || {} };
plausible.init();
</script>
<style>
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
:root, [data-theme="dark"] {
--bg: #141519; --surface: #1d1e24; --surface-hover: #2c2d33;
--border: #343741; --text: #dfe5ef; --text-muted: #98a2b3;
--primary: #fed047; --primary-hover: #fdc615;
--primary-text: #642340;
--accent: #642340;
--badge-bg: #2B394F; --badge-text: #98A8C3;
--radius: 12px;
--font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
--mono: 'Roboto Mono', 'SF Mono', 'Fira Code', Consolas, monospace;
}
[data-theme="light"] {
--bg: #f5f7fa; --surface: #ffffff; --surface-hover: #f1f3f5;
--border: #d3dae6; --text: #343741; --text-muted: #69707d;
--primary: #fed047; --primary-hover: #fdc615;
--primary-text: #642340;
--accent: #642340;
--badge-bg: #E3E8F2; --badge-text: #505F79;
}
body { font-family: var(--font); background: var(--bg); color: var(--text); min-height: 100vh; display: flex; flex-direction: column; transition: background .25s, color .25s; }
header { display: flex; align-items: center; justify-content: space-between; padding: 0 16px; height: 48px; background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 100; transition: background .25s, border-color .25s; }
.logo { display: flex; align-items: center; gap: 10px; text-decoration: none; }
.logo-svg { flex-shrink: 0; }
.logo-svg .logo-text-fill { fill: var(--text); }
.logo-badge { display: inline-flex; align-items: center; padding: 4px 16px; border-radius: 4px; border: none; background: var(--badge-bg); color: var(--badge-text); font-size: 12px; font-weight: 450; line-height: 16px; white-space: nowrap; }
.header-right { display: flex; align-items: center; gap: 8px; }
.skill-link { height: 36px; display: inline-flex; align-items: center; gap: 6px; padding: 0 12px; border: 1px solid var(--border); border-radius: 18px; background: var(--surface); color: var(--text-muted); font: 12px var(--font); text-decoration: none; transition: all .15s; cursor: pointer; }
.skill-link:hover { color: var(--text); border-color: var(--text-muted); background: var(--surface-hover); }
.skill-link svg { width: 14px; height: 14px; fill: none; stroke: currentColor; }
.su-more-tools { margin: 8px 0 0; padding: 12px 18px; text-align: center; border: 1px solid rgba(254, 208, 71, 0.35); border-radius: 12px; background: rgba(254, 208, 71, 0.06); font: 13px/1.55 var(--font); color: var(--text); transition: border-color .25s, background-color .25s, color .25s; }
.su-more-tools p { margin: 0; }
.su-more-tools a { color: var(--primary); font-weight: 700; text-decoration: none; white-space: nowrap; }
.su-more-tools a:hover { color: var(--primary-hover); text-decoration: underline; }
@media (max-width: 600px) { .su-more-tools { padding: 12px 14px; } .su-more-tools a { white-space: normal; } }
.su-noscript { max-width: 720px; margin: 24px auto; padding: 16px; border: 1px solid var(--border); border-radius: 8px; font: 14px/1.5 var(--font); background: var(--surface); color: var(--text); }
.theme-toggle { width: 36px; height: 36px; padding: 0; display: flex; align-items: center; justify-content: center; border-radius: 50%; border: 1px solid var(--border); background: var(--surface); color: var(--text-muted); cursor: pointer; transition: all .2s; }
.theme-toggle:hover { background: var(--surface-hover); color: var(--text); }
.theme-toggle svg { width: 16px; height: 16px; fill: currentColor; }
.theme-toggle .icon-sun { display: none; }
.theme-toggle .icon-moon { display: block; }
[data-theme="dark"] .theme-toggle .icon-sun { display: block; }
[data-theme="dark"] .theme-toggle .icon-moon { display: none; }
main { flex: 1; padding: 32px 16px 48px; max-width: 760px; margin: 0 auto; width: 100%; }
.page-title { font-size: 1.5rem; font-weight: 700; margin-bottom: 6px; }
.page-subtitle { color: var(--text-muted); font-size: 0.9rem; margin-bottom: 24px; line-height: 1.5; }
.page-subtitle code { font-family: var(--mono); font-size: 0.85em; padding: 1px 6px; border-radius: 4px; background: var(--surface); border: 1px solid var(--border); color: var(--text); }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px 20px; margin-bottom: 14px; transition: background .25s, border-color .25s; }
.card label { display: block; font-size: 11px; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.06em; margin-bottom: 8px; }
.label-hint { font-weight: 400; text-transform: none; letter-spacing: 0; opacity: 0.75; margin-left: 6px; }
.input, .textarea, .input-mono {
width: 100%; padding: 0 12px; border: 1px solid var(--border); border-radius: 8px;
background: var(--bg); color: var(--text); font-family: inherit; font-size: 14px;
outline: none; transition: border-color .15s, box-shadow .15s, background .25s, color .25s;
}
.input { height: 38px; }
.input-mono { height: 38px; font-family: var(--mono); font-size: 13px; }
.input-status { width: 120px; font-family: var(--mono); }
.textarea { padding: 10px 12px; font-family: var(--mono); font-size: 13px; line-height: 1.5; resize: vertical; min-height: 160px; }
.textarea-sm { min-height: 64px; font-family: var(--font); font-size: 13px; }
.input:focus, .textarea:focus, .input-mono:focus { border-color: var(--primary); box-shadow: 0 0 0 1px var(--primary); }
.input[readonly] { color: var(--text-muted); cursor: text; }
.row-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.row-head label { margin: 0; }
table { width: 100%; border-collapse: separate; border-spacing: 0 6px; }
td { padding: 0 4px 0 0; vertical-align: middle; }
td:first-child { padding-left: 0; width: 36%; }
td:last-child { padding-right: 0; width: 38px; }
.empty { color: var(--text-muted); font-size: 13px; padding: 6px 0 2px; }
.empty code { font-family: var(--mono); font-size: 0.85em; padding: 1px 6px; border-radius: 4px; background: var(--bg); border: 1px solid var(--border); color: var(--text); }
/* `height` pins the outer size so `.btn-primary`'s `font-weight: 600` doesn't
render 1-2 px taller than the regular variant via expanded bold strut
metrics. See dev/tools/AGENTS.md -> "Buttons". */
.btn { padding: 7px 14px; height: 29px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface); color: var(--text); font: 13px/1 var(--font); cursor: pointer; transition: all .15s; display: inline-flex; align-items: center; gap: 5px; white-space: nowrap; }
.btn:hover:not(:disabled) { background: var(--surface-hover); border-color: var(--text-muted); }
.btn-primary { background: var(--primary); border-color: var(--primary-text); color: var(--primary-text); font-weight: 500; }
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); border-color: var(--primary-hover); }
.btn-icon { width: 36px; height: 36px; padding: 0; justify-content: center; color: var(--text-muted); font-size: 18px; line-height: 1; }
.btn-icon:hover { color: var(--text); }
.actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; align-items: center; }
.actions .spacer { flex: 1; }
.toast { position: fixed; bottom: 20px; right: 20px; background: var(--surface); color: var(--text); padding: 10px 18px; border-radius: 8px; border: 1px solid var(--border); font-size: 13px; z-index: 200; box-shadow: 0 4px 12px rgba(0,0,0,0.3); display: flex; align-items: center; gap: 8px; animation: toastIn .2s ease; }
@keyframes toastIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }
.su-footer { text-align: center; padding: 16px; border-top: 1px solid var(--border); color: var(--text-muted); font-size: 0.8rem; transition: border-color .25s, color .25s; }
.su-footer p { margin: 0; }
.su-footer-fineprint { margin-top: 6px !important; font-size: 0.7rem; opacity: 0.75; }
.su-footer-link { background: none; border: none; padding: 0; color: inherit; font: inherit; cursor: pointer; text-decoration: underline; text-underline-offset: 2px; }
.su-footer-link:hover { color: var(--text); }
.su-dialog { max-width: 520px; width: calc(100% - 32px); max-height: calc(100% - 32px); inset: 0; margin: auto; padding: 0; border: 1px solid var(--border); border-radius: 12px; background: var(--surface); color: var(--text); box-shadow: 0 20px 60px rgba(0,0,0,0.4); }
.su-dialog::backdrop { background: rgba(0,0,0,0.45); backdrop-filter: blur(2px); }
.su-dialog-header { display: flex; align-items: center; justify-content: space-between; padding: 14px 18px; border-bottom: 1px solid var(--border); }
.su-dialog-header h2 { font-size: 1rem; font-weight: 600; }
.su-dialog-close { width: 28px; height: 28px; padding: 0; display: flex; align-items: center; justify-content: center; border-radius: 50%; border: 1px solid var(--border); background: var(--surface); color: var(--text-muted); cursor: pointer; transition: all .15s; }
.su-dialog-close:hover { background: var(--surface-hover); color: var(--text); }
.su-dialog-body { padding: 16px 18px; font-size: 0.875rem; line-height: 1.55; color: var(--text); }
.su-dialog-body p { margin-bottom: 12px; }
.su-dialog-body p:last-child { margin-bottom: 0; }
.su-dialog-body code { font-family: var(--mono); background: var(--surface-hover); padding: 1px 5px; border-radius: 4px; font-size: 0.85em; }
.su-dialog-body a { color: var(--primary); text-decoration: none; }
.su-dialog-body a:hover { text-decoration: underline; }
.su-dialog-fineprint { font-size: 0.8rem; color: var(--text-muted); }
@media (max-width: 640px) {
header { padding: 0 12px; }
.logo-svg { height: 20px; }
.logo-badge { font-size: 11px; padding: 2px 7px; }
.skill-link span { display: none; }
.skill-link { padding: 0 10px; }
main { padding: 20px 12px 32px; }
.card { padding: 14px 14px; }
.btn { padding: 6px 10px; font-size: 12px; }
td:first-child { width: 40%; }
}
</style>
</head>
<body>
<noscript>
<p class="su-noscript"><strong>HTTP Echo / Mock Response</strong> — Build a fully customizable HTTP response (status code, headers, body) and serve it as a shareable URL. Configuration stays in the URL fragment. Requires JavaScript; please enable it. Source on <a href="https://github.com/secutils-dev/secutils/blob/main/dev/tools/echo.html">GitHub</a>.</p>
</noscript>
<header>
<a class="logo" href="https://secutils.dev" target="_blank" rel="noopener">
<svg class="logo-svg" height="24" role="img" viewBox="0 0 98 16" xmlns="http://www.w3.org/2000/svg">
<path d="m3 0h10c1.662 0 3 1.338 3 3v10c0 1.662-1.338 3-3 3h-10c-1.662 0-3-1.338-3-3v-10c0-1.662 1.338-3 3-3z" fill="#fed047"/>
<path aria-label="SU" d="m11.285 12q-1.12 0-1.728-0.608-0.608-0.61867-0.608-1.6747v-5.6107h1.152v5.6q0 0.59733 0.29867 0.93867 0.29867 0.34133 0.88534 0.34133 0.58667 0 0.88534-0.34133 0.29867-0.34134 0.29867-0.93867v-5.6h1.152v5.6107q0 1.0667-0.608 1.6747t-1.728 0.608zm-6.368 0q-1.152 0-1.8453-0.608-0.69334-0.608-0.69334-1.664h1.1307q0 0.58667 0.384 0.928 0.384 0.33067 1.024 0.33067 0.62934 0 0.992-0.34133 0.36267-0.34134 0.36267-0.90667 0-0.42667-0.23467-0.74667t-0.672-0.43733l-1.12-0.29867q-0.78934-0.21333-1.248-0.77867-0.448-0.56534-0.448-1.3547 0-0.64 0.27733-1.1093 0.288-0.48 0.81067-0.74667t1.216-0.26667 1.216 0.26667q0.53334 0.26667 0.82134 0.74667 0.29867 0.46933 0.29867 1.0987h-1.1307q0-0.50133-0.34133-0.8-0.33067-0.30933-0.864-0.30933t-0.864 0.30933q-0.32 0.29867-0.32 0.78934 0 0.39467 0.21333 0.66134 0.224 0.26667 0.61867 0.37333l1.152 0.30933q0.81067 0.21333 1.28 0.832t0.46933 1.4613q0 0.69334-0.30933 1.2053-0.30933 0.50133-0.864 0.77867-0.55467 0.27733-1.312 0.27733z" fill="#642340"/>
<path class="logo-text-fill" aria-label="SECUTILS.DEV" d="m93.158 12.117-1.9733-7.7867h1.1733l1.2587 5.184q0.11733 0.46933 0.20267 0.91734 0.08533 0.448 0.128 0.69334 0.04267-0.24533 0.128-0.69334 0.096-0.45867 0.21333-0.928l1.2053-5.1733h1.184l-1.984 7.7867zm-7.8294 0v-7.7867h4.576v1.024h-3.4453v2.2187h3.072v0.992h-3.072v2.528h3.4453v1.024zm-6.5174 0v-7.7867h2.176q0.768 0 1.3333 0.29867 0.56534 0.288 0.87467 0.832 0.32 0.53334 0.32 1.248v3.008q0 0.736-0.32 1.2693-0.30933 0.53334-0.87467 0.832-0.56534 0.29867-1.3333 0.29867zm1.152-1.0347h1.024q0.62934 0 1.0027-0.36267 0.37333-0.36267 0.37333-1.0027v-3.008q0-0.61867-0.37333-0.98134-0.37334-0.37333-1.0027-0.37333h-1.024zm-5.2374 1.1413q-0.416 0-0.68267-0.24533-0.256-0.256-0.256-0.672 0-0.416 0.256-0.672 0.26667-0.26667 0.68267-0.26667 0.416 0 0.672 0.26667 0.26667 0.256 0.26667 0.672 0 0.416-0.26667 0.672-0.256 0.24533-0.672 0.24533zm-6.368 0q-1.152 0-1.8453-0.608-0.69334-0.608-0.69334-1.664h1.1307q0 0.58667 0.384 0.928 0.384 0.33067 1.024 0.33067 0.62934 0 0.992-0.34133 0.36267-0.34134 0.36267-0.90667 0-0.42667-0.23467-0.74667t-0.672-0.43733l-1.12-0.29867q-0.78934-0.21333-1.248-0.77867-0.448-0.56534-0.448-1.3547 0-0.64 0.27733-1.1093 0.288-0.48 0.81067-0.74667 0.52267-0.26667 1.216-0.26667 0.69334 0 1.216 0.26667 0.53334 0.26667 0.82134 0.74667 0.29867 0.46933 0.29867 1.0987h-1.1307q0-0.50134-0.34133-0.8-0.33067-0.30933-0.864-0.30933t-0.864 0.30933q-0.32 0.29867-0.32 0.78934 0 0.39467 0.21333 0.66134 0.224 0.26667 0.61867 0.37333l1.152 0.30933q0.81067 0.21333 1.28 0.832 0.46934 0.61867 0.46934 1.4613 0 0.69334-0.30934 1.2053-0.30933 0.50134-0.864 0.77867-0.55467 0.27733-1.312 0.27733zm-8.288-0.10667v-7.7867h1.152v6.7414h3.4027v1.0453zm-6.6987 0v-1.0453h1.568v-5.696h-1.568v-1.0453h4.32v1.0453h-1.5787v5.696h1.5787v1.0453zm-4.8214 0v-6.7414h-2.08v-1.0453h5.3227v1.0453h-2.0907v6.7414zm-5.824 0.10667q-1.12 0-1.728-0.608-0.608-0.61867-0.608-1.6747v-5.6107h1.152v5.6q0 0.59733 0.29867 0.93867 0.29867 0.34133 0.88534 0.34133 0.58667 0 0.88534-0.34133 0.29867-0.34134 0.29867-0.93867v-5.6h1.152v5.6107q0 1.0667-0.608 1.6747t-1.728 0.608zm-6.3147 0q-1.0987 0-1.7493-0.608-0.64-0.61867-0.64-1.664v-3.456q0-1.056 0.64-1.664 0.65067-0.608 1.7493-0.608 1.088 0 1.728 0.61867 0.65067 0.608 0.65067 1.6533h-1.152q0-0.608-0.33067-0.928-0.32-0.32-0.896-0.32-0.58667 0-0.91734 0.32-0.32 0.32-0.32 0.928v3.456q0 0.608 0.32 0.928 0.33067 0.32 0.91734 0.32 0.576 0 0.896-0.32 0.33067-0.32 0.33067-0.928h1.152q0 1.0453-0.65067 1.664-0.64 0.608-1.728 0.608zm-8.6827-0.10667v-7.7867h4.576v1.024h-3.4453v2.2187h3.072v0.992h-3.072v2.528h3.4453v1.024zm-4.1707 0.10667q-1.152 0-1.8453-0.608-0.69334-0.608-0.69334-1.664h1.1307q0 0.58667 0.384 0.928 0.384 0.33067 1.024 0.33067 0.62934 0 0.992-0.34133 0.36267-0.34134 0.36267-0.90667 0-0.42667-0.23467-0.74667-0.23467-0.32-0.672-0.43733l-1.12-0.29867q-0.78934-0.21333-1.248-0.77867-0.448-0.56534-0.448-1.3547 0-0.64 0.27733-1.1093 0.288-0.48 0.81067-0.74667 0.52267-0.26667 1.216-0.26667 0.69334 0 1.216 0.26667 0.53334 0.26667 0.82134 0.74667 0.29867 0.46933 0.29867 1.0987h-1.1307q0-0.50134-0.34134-0.8-0.33067-0.30933-0.864-0.30933t-0.864 0.30933q-0.32 0.29867-0.32 0.78934 0 0.39467 0.21333 0.66134 0.224 0.26667 0.61867 0.37333l1.152 0.30933q0.81067 0.21333 1.28 0.832 0.46934 0.61867 0.46934 1.4613 0 0.69334-0.30934 1.2053-0.30933 0.50134-0.864 0.77867-0.55467 0.27733-1.312 0.27733z"/>
</svg>
<span class="logo-badge">Echo</span>
</a>
<div class="header-right">
<a id="skillLink" class="skill-link" href="#" target="_blank" rel="noopener"
title="View AI agent skill (skill.md, opens in new tab)"
aria-label="View AI agent skill (opens in new tab)">
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">
<path d="M9.937 15.5A2 2 0 0 0 8.5 14.063l-6.135-1.582a.5.5 0 0 1 0-.962L8.5 9.936A2 2 0 0 0 9.937 8.5l1.582-6.135a.5.5 0 0 1 .963 0L14.063 8.5A2 2 0 0 0 15.5 9.937l6.135 1.582a.5.5 0 0 1 0 .962L15.5 14.063a2 2 0 0 0-1.437 1.437l-1.582 6.135a.5.5 0 0 1-.963 0z"/>
<path d="M20 3v4"/><path d="M22 5h-4"/><path d="M4 17v2"/><path d="M5 18H3"/>
</svg>
<span>Skill</span>
</a>
<button class="theme-toggle" id="themeToggle" aria-label="Toggle theme">
<svg class="icon-sun" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16"><path d="M8.5 15h-1v-2h1v2Zm-3.674-3.107-1.414 1.414-.707-.707 1.414-1.415.707.708Zm8.479.707-.707.707-1.414-1.414.707-.708 1.414 1.415Z"/><path fill-rule="evenodd" d="M8 4a4 4 0 1 1 0 8 4 4 0 0 1 0-8Zm0 1a3 3 0 1 0 0 6 3 3 0 0 0 0-6Z" clip-rule="evenodd"/><path d="M3.005 8.505h-2v-1h2v1Zm12 0h-2v-1h2v1ZM4.82 4.114l-.708.707-1.414-1.414.707-.707L4.82 4.114Zm8.492-.707-1.414 1.414-.708-.707L12.605 2.7l.707.707ZM8.5 3h-1V1h1v2Z"/></svg>
<svg class="icon-moon" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16"><path d="M4.05 12.95A6.982 6.982 0 0 1 2 8c0-1.79.684-3.583 2.05-4.95A6.982 6.982 0 0 1 9 1a1 1 0 0 1 .708 1.707 4.982 4.982 0 0 0-1.465 3.536 4.98 4.98 0 0 0 1.465 3.535 4.98 4.98 0 0 0 3.535 1.465 1 1 0 0 1 .707 1.707A6.981 6.981 0 0 1 9 15a6.983 6.983 0 0 1-4.95-2.05Zm.708-.707A5.983 5.983 0 0 0 9 14c1.535 0 3.07-.586 4.242-1.757a5.98 5.98 0 0 1-4.018-1.545L9 10.485a5.982 5.982 0 0 1-1.758-4.242A5.986 5.986 0 0 1 9 2a5.983 5.983 0 0 0-4.243 1.757A5.98 5.98 0 0 0 3 8l.006.288a5.978 5.978 0 0 0 1.75 3.955Z"/></svg>
</button>
</div>
</header>
<main>
<h1 class="page-title">HTTP echo response</h1>
<p class="page-subtitle">Build a mock HTTP response. Your edits are encoded in the URL fragment as you type, then served when this responder is hit with <code>?c=…</code>.</p>
<section class="card">
<label for="description">Description <span class="label-hint">(saved in URL, not sent in response)</span></label>
<textarea id="description" class="textarea textarea-sm" placeholder="What is this mock for? Notes for whoever opens the share link."></textarea>
</section>
<section class="card">
<label for="status">Status code</label>
<input id="status" class="input input-status" type="number" min="100" max="599" value="200">
</section>
<section class="card">
<div class="row-head">
<label>Headers</label>
<button id="add" type="button" class="btn">+ Add header</button>
</div>
<table id="headers"><tbody></tbody></table>
<div id="empty" class="empty" hidden>No headers. <code>Content-Type: text/plain; charset=utf-8</code> will be added automatically.</div>
</section>
<section class="card">
<label for="body">Body</label>
<textarea id="body" class="textarea" placeholder="Response body (text)"></textarea>
</section>
<section class="card">
<label for="preview">Mock URL</label>
<input id="preview" class="input input-mono" readonly>
<div class="actions">
<button id="open" type="button" class="btn btn-primary">Open mock response</button>
<button id="copy" type="button" class="btn" title="Copy the mock URL to your clipboard">
<svg viewBox="0 0 16 16" width="14" height="14" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><rect x="4" y="4" width="9" height="10" rx="1.5"/><path d="M3 11V3.5A1.5 1.5 0 0 1 4.5 2H10"/></svg>
<span class="btn-label">Copy URL</span>
</button>
<span class="spacer"></span>
<button id="reset" type="button" class="btn">Reset</button>
</div>
</section>
<aside class="su-more-tools" aria-label="More free tools">
<p>Other free, no-signup Secutils.dev tools for JWT, SAML, certificates, Markdown, and more - <a href="https://{{TOOLS_HOST}}/">Browse all tools →</a></p>
</aside>
</main>
<footer class="su-footer">
<p>Build a fully customizable HTTP response and serve it as a shareable URL.</p>
<p class="su-footer-fineprint"><button type="button" class="su-footer-link" id="privacyOpen">Privacy</button></p>
</footer>
<dialog id="privacyDialog" class="su-dialog" aria-labelledby="privacyDialogTitle">
<header class="su-dialog-header">
<h2 id="privacyDialogTitle">Privacy</h2>
<button type="button" class="su-dialog-close" id="privacyClose" aria-label="Close">
<svg viewBox="0 0 16 16" width="14" height="14" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M3 3l10 10M13 3L3 13"/></svg>
</button>
</header>
<div class="su-dialog-body">
<p><strong>Your data stays in your browser.</strong> These tools run entirely client-side. Tokens, PEMs, SAML payloads, Markdown source, and mock-response bodies are never sent to the Secutils.dev server. State that needs to survive a reload (or be shared) lives in the URL fragment (<code>#…</code>), which browsers never transmit to the server.</p>
<p><strong>Anonymous usage analytics.</strong> We use <a href="https://plausible.io/" target="_blank" rel="noopener noreferrer">Plausible Analytics</a>, a privacy-first, GDPR-compliant tool, to collect aggregate usage data. No cookies, no personal data, no individual tracking. The data is limited to top pages, referral sources, visit duration, and device-class metadata (device type, OS, country, browser). Full details in the <a href="https://plausible.io/data-policy" target="_blank" rel="noopener noreferrer">Plausible Data Policy</a>.</p>
<p class="su-dialog-fineprint">See the full <a href="https://secutils.dev/privacy" target="_blank" rel="noopener noreferrer">Secutils.dev privacy policy</a> for details on the wider service.</p>
</div>
</dialog>
<div id="toast" class="toast" role="status" aria-live="polite" style="display:none">
<span id="toastMsg"></span>
</div>
<script>
const $ = (id) => document.getElementById(id);
const els = Object.freeze({
description: $('description'),
status: $('status'),
headers: $('headers').querySelector('tbody'),
empty: $('empty'),
body: $('body'),
preview: $('preview'),
add: $('add'),
open: $('open'),
copy: $('copy'),
reset: $('reset'),
themeToggle: $('themeToggle'),
toast: $('toast'),
toastMsg: $('toastMsg'),
});
// Curated response-header suggestions surfaced via native <datalist> dropdowns.
// Names shown verbatim; values looked up case-insensitively (key = lowercased name).
// Names without an entry in HEADER_PRESETS still autocomplete the name, but offer
// no value suggestions - same for any custom (non-listed) header typed by the user.
const HEADER_NAMES = [
'Access-Control-Allow-Credentials', 'Access-Control-Allow-Headers',
'Access-Control-Allow-Methods', 'Access-Control-Allow-Origin',
'Cache-Control', 'Content-Disposition', 'Content-Encoding', 'Content-Length',
'Content-Security-Policy', 'Content-Type', 'Date', 'ETag', 'Last-Modified',
'Location', 'Server', 'Set-Cookie', 'Strict-Transport-Security', 'Vary',
'WWW-Authenticate', 'X-Content-Type-Options', 'X-Frame-Options',
];
const HEADER_PRESETS = Object.freeze({
'content-type': ['application/json; charset=utf-8', 'text/html; charset=utf-8', 'text/plain', 'application/xml', 'text/css', 'application/javascript', 'image/png', 'image/jpeg', 'application/octet-stream'],
'cache-control': ['no-cache', 'no-store', 'max-age=0', 'max-age=3600', 'public, max-age=86400', 'private', 'must-revalidate'],
'content-encoding': ['gzip', 'br', 'deflate', 'identity'],
'server': ['nginx', 'Apache', 'cloudflare', 'Microsoft-IIS/10.0'],
'access-control-allow-origin': ['*', 'https://example.com', 'null'],
'access-control-allow-methods': ['GET, POST, PUT, DELETE, OPTIONS', 'GET, HEAD, OPTIONS'],
'access-control-allow-headers': ['Content-Type, Authorization', '*'],
'access-control-allow-credentials': ['true', 'false'],
'vary': ['Accept-Encoding', 'Origin', 'Accept, Accept-Encoding', 'User-Agent'],
'content-disposition': ['inline', 'attachment', 'attachment; filename="file.pdf"'],
'strict-transport-security': ['max-age=31536000', 'max-age=31536000; includeSubDomains', 'max-age=63072000; includeSubDomains; preload'],
'x-frame-options': ['DENY', 'SAMEORIGIN'],
'x-content-type-options': ['nosniff'],
'www-authenticate': ['Bearer', 'Bearer realm="api"', 'Bearer error="invalid_token"', 'Basic realm="api"'],
'content-security-policy': [`default-src 'self'`, `default-src 'self'; script-src 'self' 'unsafe-inline'`, `frame-ancestors 'none'`],
});
// `d` is a free-text description that round-trips through the URL fragment so it's
// preserved across reloads and shared links, but the responder script ignores it
// (only `s`/`h`/`b` are sent to clients). Useful for documenting what a mock is for.
const defaultState = () => ({ d: '', s: 200, h: [['Content-Type', 'application/json']], b: '' });
let state = defaultState();
const utf8Enc = new TextEncoder();
const utf8Dec = new TextDecoder();
const toBase64Url = (bytes) => {
let s = '';
for (const b of bytes) s += String.fromCharCode(b);
return btoa(s).replace(/\+/g, '-').replace(/\//g, '_').replace(/=+$/, '');
};
const fromBase64Url = (str) => {
const b64 = str.replace(/-/g, '+').replace(/_/g, '/');
const padded = b64 + '==='.slice(0, (4 - b64.length % 4) % 4);
const bin = atob(padded);
const out = new Uint8Array(bin.length);
for (let i = 0; i < bin.length; i++) out[i] = bin.charCodeAt(i);
return out;
};
// Wire format (see dev/tools/AGENTS.md → "URL state encoding"):
// [4-byte LE u32 ulen][raw deflate bytes]. ulen lets the responder's pure-JS
// inflater (tiny-inflate) pre-allocate the output buffer in one go.
const encodeState = async (text) => {
const bytes = utf8Enc.encode(text);
const stream = new Blob([bytes]).stream().pipeThrough(new CompressionStream('deflate-raw'));
const deflated = new Uint8Array(await new Response(stream).arrayBuffer());
const out = new Uint8Array(4 + deflated.length);
new DataView(out.buffer).setUint32(0, bytes.length, true);
out.set(deflated, 4);
return toBase64Url(out);
};
const decodeState = async (str) => {
try {
const bytes = fromBase64Url(str);
if (bytes.length < 4) return null;
const stream = new Blob([bytes.subarray(4)]).stream()
.pipeThrough(new DecompressionStream('deflate-raw'));
const inflated = new Uint8Array(await new Response(stream).arrayBuffer());
return utf8Dec.decode(inflated);
} catch { return null; }
};
let syncSeq = 0;
const syncURL = async () => {
const mySeq = ++syncSeq;
const enc = await encodeState(JSON.stringify(state));
if (mySeq !== syncSeq) return;
history.replaceState(null, '', `#${enc}`);
// Echo is the one tool whose share URL must be `?c=` instead of `#`: a shared
// link is hit by the responder, which reads `context.query.c`. The fragment
// (`#`) stays browser-side for the live configurator only.
els.preview.value = `${location.origin}${location.pathname}?c=${enc}`;
};
// Shared <datalist> of response-header names - created once and reused across all
// name inputs (all rows link to the same `list="hdr-names"` target).
const namesDatalist = document.createElement('datalist');
namesDatalist.id = 'hdr-names';
for (const name of HEADER_NAMES) {
const opt = document.createElement('option');
opt.value = name;
namesDatalist.appendChild(opt);
}
document.body.appendChild(namesDatalist);
// Populate a per-row value <datalist> from HEADER_PRESETS keyed by the lowercased
// header name, and toggle the value input's `list` attribute so rows without
// presets don't render an empty dropdown indicator.
const applyValuePresets = (valueInput, valueDatalist, headerName) => {
const presets = HEADER_PRESETS[headerName.trim().toLowerCase()];
valueDatalist.replaceChildren();
if (presets) {
for (const v of presets) {
const opt = document.createElement('option');
opt.value = v;
valueDatalist.appendChild(opt);
}
valueInput.setAttribute('list', valueDatalist.id);
} else {
valueInput.removeAttribute('list');
}
};
const renderHeaders = () => {
els.headers.replaceChildren();
state.h.forEach((row, i) => {
const tr = document.createElement('tr');
const nameInput = document.createElement('input');
nameInput.className = 'input input-mono';
nameInput.placeholder = 'Header name';
nameInput.value = row[0];
nameInput.setAttribute('list', 'hdr-names');
const valueInput = document.createElement('input');
valueInput.className = 'input input-mono';
valueInput.placeholder = 'Header value';
valueInput.value = row[1];
const valueDatalist = document.createElement('datalist');
valueDatalist.id = `hdr-vals-${i}`;
applyValuePresets(valueInput, valueDatalist, row[0]);
nameInput.addEventListener('input', (e) => {
state.h[i][0] = e.target.value;
applyValuePresets(valueInput, valueDatalist, e.target.value);
syncURL();
});
valueInput.addEventListener('input', (e) => {
state.h[i][1] = e.target.value;
syncURL();
});
const tdK = document.createElement('td'); tdK.appendChild(nameInput);
const tdV = document.createElement('td');
tdV.append(valueInput, valueDatalist);
const tdRm = document.createElement('td');
const btn = document.createElement('button');
btn.type = 'button';
btn.className = 'btn btn-icon';
btn.title = 'Remove header';
btn.setAttribute('aria-label', 'Remove header');
btn.textContent = '\u00d7';
btn.addEventListener('click', () => {
state.h.splice(i, 1);
renderHeaders();
syncURL();
});
tdRm.appendChild(btn);
tr.append(tdK, tdV, tdRm);
els.headers.appendChild(tr);
});
els.empty.hidden = state.h.length > 0;
};
const render = () => {
els.description.value = state.d;
els.status.value = state.s;
els.body.value = state.b;
renderHeaders();
syncURL();
};
els.description.addEventListener('input', (e) => { state.d = e.target.value; syncURL(); });
els.status.addEventListener('input', (e) => {
const n = parseInt(e.target.value, 10);
state.s = Number.isNaN(n) ? 200 : Math.max(100, Math.min(599, n));
syncURL();
});
els.body.addEventListener('input', (e) => { state.b = e.target.value; syncURL(); });
els.add.addEventListener('click', () => {
state.h.push(['', '']);
renderHeaders();
syncURL();
});
els.open.addEventListener('click', () => {
// Preview is kept in sync after every edit, so reuse it instead of re-encoding.
// This keeps the popup-from-click heuristic happy across browsers (no async gap).
const url = els.preview.value || `${location.origin}${location.pathname}`;
window.open(url, '_blank');
});
let toastTimer;
function toast(msg) {
els.toastMsg.textContent = msg;
els.toast.style.display = 'flex';
clearTimeout(toastTimer);
toastTimer = setTimeout(() => { els.toast.style.display = 'none'; }, 2000);
}
els.copy.addEventListener('click', async () => {
try {
await navigator.clipboard.writeText(els.preview.value);
toast('Copied to clipboard');
} catch {
toast('Failed to copy');
}
});
els.reset.addEventListener('click', () => {
state = defaultState();
history.replaceState(null, '', location.pathname);
render();
});
(async () => {
if (location.hash.length > 1) {
const raw = await decodeState(location.hash.slice(1));
if (raw) {
try {
const initial = JSON.parse(raw);
state = {
d: typeof initial.d === 'string' ? initial.d : '',
s: Number.isInteger(initial.s) ? initial.s : 200,
h: Array.isArray(initial.h)
? initial.h.filter(Array.isArray).map((p) => [String(p[0] ?? ''), String(p[1] ?? '')])
: [],
b: typeof initial.b === 'string' ? initial.b : '',
};
} catch {}
}
}
render();
})();
// Skill link href: derive '<path>.md' from current URL. Index ('/') has no
// skill .md and falls back to the aggregate llms.txt; everything else maps
// `/<slug>` -> `/<slug>.md`.
{
const skillLinkEl = document.getElementById('skillLink');
if (skillLinkEl) {
const p = location.pathname;
skillLinkEl.href = (p === '/' || p === '') ? '/llms.txt' : p.replace(/\/$/, '') + '.md';
}
}
(() => {
const root = document.documentElement;
const setTheme = (t) => {
root.setAttribute('data-theme', t);
try { localStorage.setItem('su-tool-theme', t); } catch {}
};
els.themeToggle.addEventListener('click', () => {
setTheme(root.getAttribute('data-theme') === 'dark' ? 'light' : 'dark');
});
try {
const saved = localStorage.getItem('su-tool-theme');
if (saved) setTheme(saved);
else if (window.matchMedia('(prefers-color-scheme: light)').matches) setTheme('light');
} catch {}
})();
(() => {
const dlg = document.getElementById('privacyDialog');
document.getElementById('privacyOpen').addEventListener('click', () => dlg.showModal());
document.getElementById('privacyClose').addEventListener('click', () => dlg.close());
})();
</script>
</body>
</html>