@jaredwray/mockhttp 1.8.1 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +29 -7
- package/dist/index.d.mts +135 -33
- package/dist/index.mjs +360 -342
- package/package.json +22 -18
- package/site/dist/api/index.html +17983 -0
- package/site/dist/api/swagger.json +5487 -0
- package/site/dist/changelog/index.html +767 -0
- package/site/dist/changelog/page/2/index.html +578 -0
- package/site/dist/changelog/v0-1-0/index.html +453 -0
- package/site/dist/changelog/v0-2-0/index.html +437 -0
- package/site/dist/changelog/v0-2-1/index.html +438 -0
- package/site/dist/changelog/v0-2-2/index.html +436 -0
- package/site/dist/changelog/v0-2-3/index.html +440 -0
- package/site/dist/changelog/v0-3-0/index.html +443 -0
- package/site/dist/changelog/v0-4-0/index.html +437 -0
- package/site/dist/changelog/v0-4-1/index.html +441 -0
- package/site/dist/changelog/v0-4-2/index.html +446 -0
- package/site/dist/changelog/v0-4-3/index.html +437 -0
- package/site/dist/changelog/v0-5-0/index.html +443 -0
- package/site/dist/changelog/v0-6-0/index.html +444 -0
- package/site/dist/changelog/v0-6-1/index.html +441 -0
- package/site/dist/changelog/v0-7-0/index.html +445 -0
- package/site/dist/changelog/v0-8-0/index.html +440 -0
- package/site/dist/changelog/v0-9-0/index.html +437 -0
- package/site/dist/changelog/v1-0-0/index.html +446 -0
- package/site/dist/changelog/v1-0-1/index.html +437 -0
- package/site/dist/changelog/v1-1-0/index.html +445 -0
- package/site/dist/changelog/v1-2-0/index.html +443 -0
- package/site/dist/changelog/v1-3-0/index.html +448 -0
- package/site/dist/changelog/v1-4-0/index.html +445 -0
- package/site/dist/changelog/v1-5-0/index.html +439 -0
- package/site/dist/changelog/v1-5-1/index.html +443 -0
- package/site/dist/changelog/v1-6-0/index.html +467 -0
- package/site/dist/changelog/v1-7-0/index.html +462 -0
- package/site/dist/changelog/v1-8-0/index.html +481 -0
- package/site/dist/changelog/v1-8-1/index.html +457 -0
- package/site/dist/changelog/v1-9-0/index.html +495 -0
- package/site/dist/changelog/v2-0-0/index.html +500 -0
- package/site/dist/changelog-latest.json +269 -0
- package/site/dist/changelog.json +399 -0
- package/site/dist/css/api.css +1113 -0
- package/site/dist/css/highlight/highlight.min.js +1433 -0
- package/site/dist/css/highlight/styles/base16/docula.css +123 -0
- package/site/dist/css/home.css +133 -0
- package/site/dist/css/styles.css +1227 -0
- package/site/dist/css/variables.css +32 -0
- package/site/dist/docs/bins/index.html +942 -0
- package/site/dist/docs/configuration/index.html +771 -0
- package/site/dist/docs/hosted/index.html +544 -0
- package/site/dist/docs/https/index.html +758 -0
- package/site/dist/docs/index.html +601 -0
- package/site/dist/docs/library/index.html +780 -0
- package/site/dist/docs/taps/index.html +708 -0
- package/site/dist/favicon.svg +14 -0
- package/site/dist/feed.xml +1 -0
- package/site/dist/index.html +601 -0
- package/site/dist/js/api.js +363 -0
- package/site/dist/js/search.js +436 -0
- package/site/dist/llms-full.txt +7415 -0
- package/site/dist/llms.txt +40 -0
- package/site/dist/logo.svg +21 -0
- package/site/dist/robots.txt +2 -0
- package/site/dist/search-index.json +1 -0
- package/site/dist/sitemap.xml +1 -0
|
@@ -0,0 +1,758 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
|
|
4
|
+
<head>
|
|
5
|
+
<meta charset="UTF-8">
|
|
6
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
7
|
+
<meta name="description" content="HTTP mock server and httpbin replacement for API testing. Run it at mockhttp.org, in Docker, or in Node.js.">
|
|
8
|
+
<link rel="stylesheet" href="/css/variables.css">
|
|
9
|
+
<link rel="stylesheet" href="/css/styles.css">
|
|
10
|
+
<link rel="stylesheet" href="/css/highlight/styles/base16/docula.css">
|
|
11
|
+
<link rel="icon" href="/logo.svg">
|
|
12
|
+
<script>
|
|
13
|
+
(function(){
|
|
14
|
+
window.__doculaThemeKey = 'docula:theme:' + ('https://mockhttp.org').replace(/^https?:\/\//, '');
|
|
15
|
+
var mode = localStorage.getItem(window.__doculaThemeKey) || 'light';
|
|
16
|
+
var resolved = mode === 'system'
|
|
17
|
+
? (window.matchMedia('(prefers-color-scheme: light)').matches ? 'light' : 'dark')
|
|
18
|
+
: mode;
|
|
19
|
+
if (resolved === 'light') document.documentElement.setAttribute('data-theme', 'light');
|
|
20
|
+
try {
|
|
21
|
+
var authState = JSON.parse(localStorage.getItem('docula-auth-state'));
|
|
22
|
+
if (authState) {
|
|
23
|
+
window.__doculaAuth = authState;
|
|
24
|
+
if (authState.loggedIn) {
|
|
25
|
+
document.documentElement.classList.add('docula-auth-logged-in');
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
} catch (e) {
|
|
29
|
+
// Ignore localStorage parsing errors
|
|
30
|
+
}
|
|
31
|
+
if (!window.__doculaAuth) {
|
|
32
|
+
window.__doculaAuth = { loggedIn: false, displayName: null };
|
|
33
|
+
}
|
|
34
|
+
})();
|
|
35
|
+
</script>
|
|
36
|
+
<title>MockHTTP - HTTPS and HTTP/2</title>
|
|
37
|
+
<script type="application/ld+json">
|
|
38
|
+
{"@context":"https://schema.org","@type":"TechArticle","headline":"HTTPS and HTTP/2","description":"","url":"https://mockhttp.org/docs/https/","publisher":{"@type":"Organization","name":"MockHTTP"},"dateModified":"2026-09-18","keywords":[]}
|
|
39
|
+
</script>
|
|
40
|
+
</head>
|
|
41
|
+
|
|
42
|
+
<body>
|
|
43
|
+
<header class="header">
|
|
44
|
+
<div class="header-top">
|
|
45
|
+
<div class="header-top__content">
|
|
46
|
+
<button class="mobile-menu-toggle" id="mobile-menu-toggle" aria-label="Toggle navigation menu">
|
|
47
|
+
<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><line x1="4" x2="20" y1="12" y2="12"/><line x1="4" x2="20" y1="6" y2="6"/><line x1="4" x2="20" y1="18" y2="18"/></svg>
|
|
48
|
+
</button>
|
|
49
|
+
<a href="/" class="logo-link">
|
|
50
|
+
<img alt="MockHTTP" class="logo__img" src="/logo.svg">
|
|
51
|
+
</a>
|
|
52
|
+
<nav class="header-bottom__nav">
|
|
53
|
+
<a class="header-bottom__item" href="/docs/" id="nav-docs">
|
|
54
|
+
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M12 7v14"/><path d="M3 18a1 1 0 0 1-1-1V4a1 1 0 0 1 1-1h5a4 4 0 0 1 4 4 4 4 0 0 1 4-4h5a1 1 0 0 1 1 1v13a1 1 0 0 1-1 1h-6a3 3 0 0 0-3 3 3 3 0 0 0-3-3z"/></svg>
|
|
55
|
+
<span>Documentation</span>
|
|
56
|
+
</a>
|
|
57
|
+
<a class="header-bottom__item" href="/api" id="nav-api">
|
|
58
|
+
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="m16 18 6-6-6-6"/><path d="m8 6-6 6 6 6"/></svg>
|
|
59
|
+
<span>API Reference</span>
|
|
60
|
+
</a>
|
|
61
|
+
<a class="header-bottom__item" href="/changelog/" id="nav-changelog">
|
|
62
|
+
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M11 6a13 13 0 0 0 8.4-2.8A1 1 0 0 1 21 4v12a1 1 0 0 1-1.6.8A13 13 0 0 0 11 14H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2z"/><path d="M6 14a12 12 0 0 0 2.4 7.2 2 2 0 0 0 3.2-2.4A8 8 0 0 1 10 14"/><path d="M8 6v8"/></svg>
|
|
63
|
+
<span>Changelog</span>
|
|
64
|
+
</a>
|
|
65
|
+
</nav>
|
|
66
|
+
<div class="header-actions">
|
|
67
|
+
<button class="search-button" id="search-button" type="button" aria-label="Search" aria-keyshortcuts="Meta+K Control+K">
|
|
68
|
+
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="11" cy="11" r="8"/><path d="m21 21-4.3-4.3"/></svg>
|
|
69
|
+
<span class="search-button__text">Search</span>
|
|
70
|
+
<span class="search-button__shortcut">⌘K</span>
|
|
71
|
+
</button>
|
|
72
|
+
<button class="theme-button" id="theme-toggle" aria-label="Theme: system (following system)">
|
|
73
|
+
<svg class="theme-button__icon theme-button__icon--system" xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="2" y="3" width="20" height="14" rx="2"/><line x1="8" x2="16" y1="21" y2="21"/><line x1="12" x2="12" y1="17" y2="21"/></svg>
|
|
74
|
+
<svg class="theme-button__icon theme-button__icon--sun theme-button__icon--hidden" xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="4"/><path d="M12 2v2"/><path d="M12 20v2"/><path d="m4.93 4.93 1.41 1.41"/><path d="m17.66 17.66 1.41 1.41"/><path d="M2 12h2"/><path d="M20 12h2"/><path d="m6.34 17.66-1.41 1.41"/><path d="m19.07 4.93-1.41 1.41"/></svg>
|
|
75
|
+
<svg class="theme-button__icon theme-button__icon--moon theme-button__icon--hidden" xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M20.985 12.486a9 9 0 1 1-9.473-9.472c.405-.022.617.46.402.803a6 6 0 0 0 8.268 8.268c.344-.215.825-.004.803.401"/></svg>
|
|
76
|
+
</button>
|
|
77
|
+
</div>
|
|
78
|
+
</div>
|
|
79
|
+
</div>
|
|
80
|
+
</header>
|
|
81
|
+
<aside class="mobile-sidebar" id="mobile-sidebar">
|
|
82
|
+
<nav class="mobile-nav">
|
|
83
|
+
<a class="mobile-nav__item" href="/docs/">
|
|
84
|
+
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M12 7v14"/><path d="M3 18a1 1 0 0 1-1-1V4a1 1 0 0 1 1-1h5a4 4 0 0 1 4 4 4 4 0 0 1 4-4h5a1 1 0 0 1 1 1v13a1 1 0 0 1-1 1h-6a3 3 0 0 0-3 3 3 3 0 0 0-3-3z"/></svg>
|
|
85
|
+
<span>Documentation</span>
|
|
86
|
+
</a>
|
|
87
|
+
<a class="mobile-nav__item" href="/api">
|
|
88
|
+
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="m16 18 6-6-6-6"/><path d="m8 6-6 6 6 6"/></svg>
|
|
89
|
+
<span>API Reference</span>
|
|
90
|
+
</a>
|
|
91
|
+
<a class="mobile-nav__item" href="/changelog/">
|
|
92
|
+
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M11 6a13 13 0 0 0 8.4-2.8A1 1 0 0 1 21 4v12a1 1 0 0 1-1.6.8A13 13 0 0 0 11 14H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2z"/><path d="M6 14a12 12 0 0 0 2.4 7.2 2 2 0 0 0 3.2-2.4A8 8 0 0 1 10 14"/><path d="M8 6v8"/></svg>
|
|
93
|
+
<span>Changelog</span>
|
|
94
|
+
</a>
|
|
95
|
+
</nav>
|
|
96
|
+
<div class="mobile-sidebar__docs" id="mobile-sidebar-docs"></div>
|
|
97
|
+
</aside>
|
|
98
|
+
<div class="sidebar-backdrop" id="sidebar-backdrop"></div>
|
|
99
|
+
<div class="search-modal" id="search-modal" hidden>
|
|
100
|
+
<div class="search-modal__backdrop" data-search-close></div>
|
|
101
|
+
<div class="search-modal__panel" role="dialog" aria-modal="true" aria-label="Search">
|
|
102
|
+
<div class="search-modal__header">
|
|
103
|
+
<svg class="search-modal__icon" xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="11" cy="11" r="8"/><path d="m21 21-4.3-4.3"/></svg>
|
|
104
|
+
<input
|
|
105
|
+
type="search"
|
|
106
|
+
id="search-input"
|
|
107
|
+
class="search-modal__input"
|
|
108
|
+
placeholder="Search"
|
|
109
|
+
autocomplete="off"
|
|
110
|
+
autocorrect="off"
|
|
111
|
+
autocapitalize="off"
|
|
112
|
+
spellcheck="false"
|
|
113
|
+
aria-label="Search"
|
|
114
|
+
aria-controls="search-results"
|
|
115
|
+
aria-activedescendant=""
|
|
116
|
+
role="combobox"
|
|
117
|
+
aria-expanded="true"
|
|
118
|
+
/>
|
|
119
|
+
<button class="search-modal__clear" id="search-clear" type="button" aria-label="Clear search" hidden>
|
|
120
|
+
<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><line x1="18" y1="6" x2="6" y2="18"/><line x1="6" y1="6" x2="18" y2="18"/></svg>
|
|
121
|
+
</button>
|
|
122
|
+
</div>
|
|
123
|
+
<div class="search-modal__body">
|
|
124
|
+
<ul class="search-results" id="search-results" role="listbox" aria-label="Search results"></ul>
|
|
125
|
+
<div class="search-modal__empty" id="search-empty" hidden>
|
|
126
|
+
No results for "<span class="search-modal__empty-query" id="search-empty-query"></span>"
|
|
127
|
+
</div>
|
|
128
|
+
<div class="search-modal__initial" id="search-initial">
|
|
129
|
+
Type to search the documentation.
|
|
130
|
+
</div>
|
|
131
|
+
</div>
|
|
132
|
+
<div class="search-modal__footer">
|
|
133
|
+
<span class="search-modal__hint"><kbd class="search-modal__kbd">↑</kbd><kbd class="search-modal__kbd">↓</kbd> to navigate</span>
|
|
134
|
+
<span class="search-modal__hint"><kbd class="search-modal__kbd">↵</kbd> to select</span>
|
|
135
|
+
<span class="search-modal__hint"><kbd class="search-modal__kbd">esc</kbd> to close</span>
|
|
136
|
+
</div>
|
|
137
|
+
</div>
|
|
138
|
+
</div>
|
|
139
|
+
<script>
|
|
140
|
+
window.__doculaSearch = { indexUrl: "/search-index.json" };
|
|
141
|
+
</script>
|
|
142
|
+
<script src="/js/search.js" defer></script>
|
|
143
|
+
<div class="page-dropdown" id="page-dropdown">
|
|
144
|
+
<button class="page-dropdown__toggle" id="page-dropdown-toggle">
|
|
145
|
+
<span class="page-dropdown__title">HTTPS and HTTP/2</span>
|
|
146
|
+
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="m7 15 5 5 5-5"/><path d="m7 9 5-5 5 5"/></svg>
|
|
147
|
+
</button>
|
|
148
|
+
<div class="page-dropdown__list" id="page-dropdown-list">
|
|
149
|
+
<section class="nav-sidebar__section">
|
|
150
|
+
<ul class="nav-sidebar__list">
|
|
151
|
+
<li>
|
|
152
|
+
<a href="/docs/" class="nav-sidebar__item">Getting Started</a>
|
|
153
|
+
</li>
|
|
154
|
+
</ul>
|
|
155
|
+
</section>
|
|
156
|
+
<section class="nav-sidebar__section">
|
|
157
|
+
<ul class="nav-sidebar__list">
|
|
158
|
+
<li>
|
|
159
|
+
<a href="/docs/https/" class="nav-sidebar__item">HTTPS and HTTP/2</a>
|
|
160
|
+
</li>
|
|
161
|
+
</ul>
|
|
162
|
+
</section>
|
|
163
|
+
<section class="nav-sidebar__section">
|
|
164
|
+
<ul class="nav-sidebar__list">
|
|
165
|
+
<li>
|
|
166
|
+
<a href="/docs/taps/" class="nav-sidebar__item">Taps</a>
|
|
167
|
+
</li>
|
|
168
|
+
</ul>
|
|
169
|
+
</section>
|
|
170
|
+
<section class="nav-sidebar__section">
|
|
171
|
+
<ul class="nav-sidebar__list">
|
|
172
|
+
<li>
|
|
173
|
+
<a href="/docs/bins/" class="nav-sidebar__item">Bins</a>
|
|
174
|
+
</li>
|
|
175
|
+
</ul>
|
|
176
|
+
</section>
|
|
177
|
+
<section class="nav-sidebar__section">
|
|
178
|
+
<ul class="nav-sidebar__list">
|
|
179
|
+
<li>
|
|
180
|
+
<a href="/docs/configuration/" class="nav-sidebar__item">Configuration</a>
|
|
181
|
+
</li>
|
|
182
|
+
</ul>
|
|
183
|
+
</section>
|
|
184
|
+
<section class="nav-sidebar__section">
|
|
185
|
+
<ul class="nav-sidebar__list">
|
|
186
|
+
<li>
|
|
187
|
+
<a href="/docs/library/" class="nav-sidebar__item">Library API</a>
|
|
188
|
+
</li>
|
|
189
|
+
</ul>
|
|
190
|
+
</section>
|
|
191
|
+
<section class="nav-sidebar__section">
|
|
192
|
+
<ul class="nav-sidebar__list">
|
|
193
|
+
<li>
|
|
194
|
+
<a href="/docs/hosted/" class="nav-sidebar__item">Hosted Service</a>
|
|
195
|
+
</li>
|
|
196
|
+
</ul>
|
|
197
|
+
</section>
|
|
198
|
+
</div>
|
|
199
|
+
</div>
|
|
200
|
+
<div class="content">
|
|
201
|
+
<aside class="nav-sidebar" id="nav-sidebar">
|
|
202
|
+
<section class="nav-sidebar__section">
|
|
203
|
+
<ul class="nav-sidebar__list">
|
|
204
|
+
<li>
|
|
205
|
+
<a href="/docs/" class="nav-sidebar__item">Getting Started</a>
|
|
206
|
+
</li>
|
|
207
|
+
</ul>
|
|
208
|
+
</section>
|
|
209
|
+
<section class="nav-sidebar__section">
|
|
210
|
+
<ul class="nav-sidebar__list">
|
|
211
|
+
<li>
|
|
212
|
+
<a href="/docs/https/" class="nav-sidebar__item">HTTPS and HTTP/2</a>
|
|
213
|
+
</li>
|
|
214
|
+
</ul>
|
|
215
|
+
</section>
|
|
216
|
+
<section class="nav-sidebar__section">
|
|
217
|
+
<ul class="nav-sidebar__list">
|
|
218
|
+
<li>
|
|
219
|
+
<a href="/docs/taps/" class="nav-sidebar__item">Taps</a>
|
|
220
|
+
</li>
|
|
221
|
+
</ul>
|
|
222
|
+
</section>
|
|
223
|
+
<section class="nav-sidebar__section">
|
|
224
|
+
<ul class="nav-sidebar__list">
|
|
225
|
+
<li>
|
|
226
|
+
<a href="/docs/bins/" class="nav-sidebar__item">Bins</a>
|
|
227
|
+
</li>
|
|
228
|
+
</ul>
|
|
229
|
+
</section>
|
|
230
|
+
<section class="nav-sidebar__section">
|
|
231
|
+
<ul class="nav-sidebar__list">
|
|
232
|
+
<li>
|
|
233
|
+
<a href="/docs/configuration/" class="nav-sidebar__item">Configuration</a>
|
|
234
|
+
</li>
|
|
235
|
+
</ul>
|
|
236
|
+
</section>
|
|
237
|
+
<section class="nav-sidebar__section">
|
|
238
|
+
<ul class="nav-sidebar__list">
|
|
239
|
+
<li>
|
|
240
|
+
<a href="/docs/library/" class="nav-sidebar__item">Library API</a>
|
|
241
|
+
</li>
|
|
242
|
+
</ul>
|
|
243
|
+
</section>
|
|
244
|
+
<section class="nav-sidebar__section">
|
|
245
|
+
<ul class="nav-sidebar__list">
|
|
246
|
+
<li>
|
|
247
|
+
<a href="/docs/hosted/" class="nav-sidebar__item">Hosted Service</a>
|
|
248
|
+
</li>
|
|
249
|
+
</ul>
|
|
250
|
+
</section>
|
|
251
|
+
</aside>
|
|
252
|
+
<article class="article">
|
|
253
|
+
<header class="article__header">
|
|
254
|
+
<h1 class="article__title">HTTPS and HTTP/2</h1>
|
|
255
|
+
</header>
|
|
256
|
+
<div class="article__body">
|
|
257
|
+
<main class="article__main">
|
|
258
|
+
<p>MockHttp supports HTTPS with auto-generated self-signed certificates or your own custom certificates. No external dependencies are required — certificate generation uses only Node.js built-in <code>crypto</code>.</p>
|
|
259
|
+
<h2 id="table-of-contents">Table of Contents</h2>
|
|
260
|
+
<ul>
|
|
261
|
+
<li>
|
|
262
|
+
<ul>
|
|
263
|
+
<li><a href="#auto-generated-certificate">Auto-Generated Certificate</a></li>
|
|
264
|
+
<li><a href="#custom-certificate-options">Custom Certificate Options</a></li>
|
|
265
|
+
<li><a href="#provide-your-own-certificate">Provide Your Own Certificate</a></li>
|
|
266
|
+
<li><a href="#standalone-certificate-generation">Standalone Certificate Generation</a></li>
|
|
267
|
+
<li><a href="#https-options-reference">HTTPS Options Reference</a>
|
|
268
|
+
<ul>
|
|
269
|
+
<li><a href="#certificate-options">Certificate Options</a></li>
|
|
270
|
+
</ul>
|
|
271
|
+
</li>
|
|
272
|
+
</ul>
|
|
273
|
+
</li>
|
|
274
|
+
<li><a href="#http2-support">HTTP/2 Support</a>
|
|
275
|
+
<ul>
|
|
276
|
+
<li><a href="#http2-over-tls-h2">HTTP/2 over TLS (h2)</a></li>
|
|
277
|
+
<li><a href="#http2-cleartext-h2c">HTTP/2 Cleartext (h2c)</a></li>
|
|
278
|
+
<li><a href="#http2-via-environment-variable">HTTP/2 via Environment Variable</a></li>
|
|
279
|
+
</ul>
|
|
280
|
+
</li>
|
|
281
|
+
</ul>
|
|
282
|
+
<h2 id="auto-generated-certificate">Auto-Generated Certificate</h2>
|
|
283
|
+
<p>The simplest way to enable HTTPS is to pass <code>https: true</code>. A self-signed certificate for <code>localhost</code> is generated automatically:</p>
|
|
284
|
+
<pre><code class="hljs language-javascript"><span class="hljs-keyword">import</span> { <span class="hljs-title class_">MockHttp</span> } <span class="hljs-keyword">from</span> <span class="hljs-string">'@jaredwray/mockhttp'</span>;
|
|
285
|
+
|
|
286
|
+
<span class="hljs-keyword">const</span> mock = <span class="hljs-keyword">new</span> <span class="hljs-title class_">MockHttp</span>({ <span class="hljs-attr">https</span>: <span class="hljs-literal">true</span> });
|
|
287
|
+
<span class="hljs-keyword">await</span> mock.<span class="hljs-title function_">start</span>();
|
|
288
|
+
|
|
289
|
+
<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(mock.<span class="hljs-property">isHttps</span>); <span class="hljs-comment">// true</span>
|
|
290
|
+
|
|
291
|
+
<span class="hljs-comment">// Use Fastify's built-in inject() for testing (no TLS setup needed)</span>
|
|
292
|
+
<span class="hljs-keyword">const</span> response = <span class="hljs-keyword">await</span> mock.<span class="hljs-property">server</span>.<span class="hljs-title function_">inject</span>({ <span class="hljs-attr">method</span>: <span class="hljs-string">'GET'</span>, <span class="hljs-attr">url</span>: <span class="hljs-string">'/get'</span> });
|
|
293
|
+
<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(response.<span class="hljs-property">statusCode</span>); <span class="hljs-comment">// 200</span>
|
|
294
|
+
|
|
295
|
+
<span class="hljs-keyword">await</span> mock.<span class="hljs-title function_">close</span>();
|
|
296
|
+
</code></pre>
|
|
297
|
+
<blockquote>
|
|
298
|
+
<p><strong>Note:</strong> Self-signed certificates are not trusted by default. When making real HTTPS requests (e.g. with <code>fetch</code>), set <code>NODE_TLS_REJECT_UNAUTHORIZED=0</code> in your test environment or use a custom HTTPS agent.</p>
|
|
299
|
+
</blockquote>
|
|
300
|
+
<h2 id="custom-certificate-options">Custom Certificate Options</h2>
|
|
301
|
+
<p>You can customize the auto-generated certificate by passing <code>certificateOptions</code>:</p>
|
|
302
|
+
<pre><code class="hljs language-javascript"><span class="hljs-keyword">const</span> mock = <span class="hljs-keyword">new</span> <span class="hljs-title class_">MockHttp</span>({
|
|
303
|
+
<span class="hljs-attr">https</span>: {
|
|
304
|
+
<span class="hljs-attr">certificateOptions</span>: {
|
|
305
|
+
<span class="hljs-attr">commonName</span>: <span class="hljs-string">'my-test-server'</span>,
|
|
306
|
+
<span class="hljs-attr">validityDays</span>: <span class="hljs-number">30</span>,
|
|
307
|
+
<span class="hljs-attr">keySize</span>: <span class="hljs-number">4096</span>,
|
|
308
|
+
<span class="hljs-attr">altNames</span>: [
|
|
309
|
+
{ <span class="hljs-attr">type</span>: <span class="hljs-string">'dns'</span>, <span class="hljs-attr">value</span>: <span class="hljs-string">'example.local'</span> },
|
|
310
|
+
{ <span class="hljs-attr">type</span>: <span class="hljs-string">'dns'</span>, <span class="hljs-attr">value</span>: <span class="hljs-string">'*.example.local'</span> },
|
|
311
|
+
{ <span class="hljs-attr">type</span>: <span class="hljs-string">'ip'</span>, <span class="hljs-attr">value</span>: <span class="hljs-string">'192.168.1.100'</span> },
|
|
312
|
+
],
|
|
313
|
+
},
|
|
314
|
+
},
|
|
315
|
+
});
|
|
316
|
+
|
|
317
|
+
<span class="hljs-keyword">await</span> mock.<span class="hljs-title function_">start</span>();
|
|
318
|
+
<span class="hljs-comment">// Make requests...</span>
|
|
319
|
+
<span class="hljs-keyword">await</span> mock.<span class="hljs-title function_">close</span>();
|
|
320
|
+
</code></pre>
|
|
321
|
+
<h2 id="provide-your-own-certificate">Provide Your Own Certificate</h2>
|
|
322
|
+
<p>You can supply your own PEM-encoded certificate and key, either as strings or file paths:</p>
|
|
323
|
+
<pre><code class="hljs language-javascript"><span class="hljs-comment">// Using PEM strings</span>
|
|
324
|
+
<span class="hljs-keyword">const</span> mock = <span class="hljs-keyword">new</span> <span class="hljs-title class_">MockHttp</span>({
|
|
325
|
+
<span class="hljs-attr">https</span>: {
|
|
326
|
+
<span class="hljs-attr">cert</span>: <span class="hljs-string">'-----BEGIN CERTIFICATE-----\n...'</span>,
|
|
327
|
+
<span class="hljs-attr">key</span>: <span class="hljs-string">'-----BEGIN PRIVATE KEY-----\n...'</span>,
|
|
328
|
+
},
|
|
329
|
+
});
|
|
330
|
+
<span class="hljs-keyword">await</span> mock.<span class="hljs-title function_">start</span>();
|
|
331
|
+
<span class="hljs-comment">// Make requests...</span>
|
|
332
|
+
<span class="hljs-keyword">await</span> mock.<span class="hljs-title function_">close</span>();
|
|
333
|
+
</code></pre>
|
|
334
|
+
<pre><code class="hljs language-javascript"><span class="hljs-comment">// Using file paths</span>
|
|
335
|
+
<span class="hljs-keyword">const</span> mock = <span class="hljs-keyword">new</span> <span class="hljs-title class_">MockHttp</span>({
|
|
336
|
+
<span class="hljs-attr">https</span>: {
|
|
337
|
+
<span class="hljs-attr">cert</span>: <span class="hljs-string">'/path/to/cert.pem'</span>,
|
|
338
|
+
<span class="hljs-attr">key</span>: <span class="hljs-string">'/path/to/key.pem'</span>,
|
|
339
|
+
},
|
|
340
|
+
});
|
|
341
|
+
<span class="hljs-keyword">await</span> mock.<span class="hljs-title function_">start</span>();
|
|
342
|
+
<span class="hljs-comment">// Make requests...</span>
|
|
343
|
+
<span class="hljs-keyword">await</span> mock.<span class="hljs-title function_">close</span>();
|
|
344
|
+
</code></pre>
|
|
345
|
+
<h2 id="standalone-certificate-generation">Standalone Certificate Generation</h2>
|
|
346
|
+
<p>You can also generate certificates independently using the exported utility functions:</p>
|
|
347
|
+
<pre><code class="hljs language-javascript"><span class="hljs-keyword">import</span> { generateCertificate, generateCertificateFiles } <span class="hljs-keyword">from</span> <span class="hljs-string">'@jaredwray/mockhttp'</span>;
|
|
348
|
+
|
|
349
|
+
<span class="hljs-comment">// Generate in-memory PEM strings</span>
|
|
350
|
+
<span class="hljs-keyword">const</span> { cert, key } = <span class="hljs-title function_">generateCertificate</span>({
|
|
351
|
+
<span class="hljs-attr">commonName</span>: <span class="hljs-string">'my-app'</span>,
|
|
352
|
+
<span class="hljs-attr">validityDays</span>: <span class="hljs-number">90</span>,
|
|
353
|
+
});
|
|
354
|
+
|
|
355
|
+
<span class="hljs-comment">// Generate and write to disk</span>
|
|
356
|
+
<span class="hljs-keyword">const</span> result = <span class="hljs-keyword">await</span> <span class="hljs-title function_">generateCertificateFiles</span>({
|
|
357
|
+
<span class="hljs-attr">certPath</span>: <span class="hljs-string">'./certs/cert.pem'</span>,
|
|
358
|
+
<span class="hljs-attr">keyPath</span>: <span class="hljs-string">'./certs/key.pem'</span>,
|
|
359
|
+
<span class="hljs-attr">commonName</span>: <span class="hljs-string">'my-app'</span>,
|
|
360
|
+
});
|
|
361
|
+
</code></pre>
|
|
362
|
+
<h2 id="https-options-reference">HTTPS Options Reference</h2>
|
|
363
|
+
<table>
|
|
364
|
+
<thead>
|
|
365
|
+
<tr>
|
|
366
|
+
<th>Option</th>
|
|
367
|
+
<th>Type</th>
|
|
368
|
+
<th>Default</th>
|
|
369
|
+
<th>Description</th>
|
|
370
|
+
</tr>
|
|
371
|
+
</thead>
|
|
372
|
+
<tbody>
|
|
373
|
+
<tr>
|
|
374
|
+
<td><code>cert</code></td>
|
|
375
|
+
<td>string</td>
|
|
376
|
+
<td>—</td>
|
|
377
|
+
<td>PEM-encoded certificate string or file path</td>
|
|
378
|
+
</tr>
|
|
379
|
+
<tr>
|
|
380
|
+
<td><code>key</code></td>
|
|
381
|
+
<td>string</td>
|
|
382
|
+
<td>—</td>
|
|
383
|
+
<td>PEM-encoded private key string or file path</td>
|
|
384
|
+
</tr>
|
|
385
|
+
<tr>
|
|
386
|
+
<td><code>autoGenerate</code></td>
|
|
387
|
+
<td>boolean</td>
|
|
388
|
+
<td><code>true</code></td>
|
|
389
|
+
<td>Auto-generate a self-signed certificate when cert/key are not provided</td>
|
|
390
|
+
</tr>
|
|
391
|
+
<tr>
|
|
392
|
+
<td><code>certificateOptions</code></td>
|
|
393
|
+
<td>CertificateOptions</td>
|
|
394
|
+
<td>—</td>
|
|
395
|
+
<td>Options for the auto-generated certificate</td>
|
|
396
|
+
</tr>
|
|
397
|
+
</tbody>
|
|
398
|
+
</table>
|
|
399
|
+
<h3 id="certificate-options">Certificate Options</h3>
|
|
400
|
+
<table>
|
|
401
|
+
<thead>
|
|
402
|
+
<tr>
|
|
403
|
+
<th>Option</th>
|
|
404
|
+
<th>Type</th>
|
|
405
|
+
<th>Default</th>
|
|
406
|
+
<th>Description</th>
|
|
407
|
+
</tr>
|
|
408
|
+
</thead>
|
|
409
|
+
<tbody>
|
|
410
|
+
<tr>
|
|
411
|
+
<td><code>commonName</code></td>
|
|
412
|
+
<td>string</td>
|
|
413
|
+
<td><code>'localhost'</code></td>
|
|
414
|
+
<td>Certificate subject Common Name (CN)</td>
|
|
415
|
+
</tr>
|
|
416
|
+
<tr>
|
|
417
|
+
<td><code>altNames</code></td>
|
|
418
|
+
<td>Array<{ type, value }></td>
|
|
419
|
+
<td><code>[dns:localhost, ip:127.0.0.1, ip:::1]</code></td>
|
|
420
|
+
<td>Subject Alternative Names with type <code>'dns'</code> or <code>'ip'</code></td>
|
|
421
|
+
</tr>
|
|
422
|
+
<tr>
|
|
423
|
+
<td><code>validityDays</code></td>
|
|
424
|
+
<td>number</td>
|
|
425
|
+
<td><code>365</code></td>
|
|
426
|
+
<td>Certificate validity period in days</td>
|
|
427
|
+
</tr>
|
|
428
|
+
<tr>
|
|
429
|
+
<td><code>keySize</code></td>
|
|
430
|
+
<td>number</td>
|
|
431
|
+
<td><code>2048</code></td>
|
|
432
|
+
<td>RSA key size in bits</td>
|
|
433
|
+
</tr>
|
|
434
|
+
</tbody>
|
|
435
|
+
</table>
|
|
436
|
+
<h1 id="http2-support">HTTP/2 Support</h1>
|
|
437
|
+
<p>MockHttp supports HTTP/2 in two modes:</p>
|
|
438
|
+
<ul>
|
|
439
|
+
<li><strong>h2</strong> — HTTP/2 over TLS (used by browsers), enabled with both <code>http2: true</code> and <code>https: true</code></li>
|
|
440
|
+
<li><strong>h2c</strong> — HTTP/2 cleartext (no TLS), enabled with just <code>http2: true</code>, useful for service-to-service testing</li>
|
|
441
|
+
</ul>
|
|
442
|
+
<h2 id="http2-over-tls-h2">HTTP/2 over TLS (h2)</h2>
|
|
443
|
+
<pre><code class="hljs language-javascript"><span class="hljs-keyword">import</span> { <span class="hljs-title class_">MockHttp</span> } <span class="hljs-keyword">from</span> <span class="hljs-string">'@jaredwray/mockhttp'</span>;
|
|
444
|
+
|
|
445
|
+
<span class="hljs-keyword">const</span> mock = <span class="hljs-keyword">new</span> <span class="hljs-title class_">MockHttp</span>({ <span class="hljs-attr">http2</span>: <span class="hljs-literal">true</span>, <span class="hljs-attr">https</span>: <span class="hljs-literal">true</span> });
|
|
446
|
+
<span class="hljs-keyword">await</span> mock.<span class="hljs-title function_">start</span>();
|
|
447
|
+
|
|
448
|
+
<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(mock.<span class="hljs-property">http2</span>); <span class="hljs-comment">// true</span>
|
|
449
|
+
<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(mock.<span class="hljs-property">isHttps</span>); <span class="hljs-comment">// true</span>
|
|
450
|
+
|
|
451
|
+
<span class="hljs-keyword">const</span> response = <span class="hljs-keyword">await</span> mock.<span class="hljs-property">server</span>.<span class="hljs-title function_">inject</span>({ <span class="hljs-attr">method</span>: <span class="hljs-string">'GET'</span>, <span class="hljs-attr">url</span>: <span class="hljs-string">'/get'</span> });
|
|
452
|
+
<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(response.<span class="hljs-property">statusCode</span>); <span class="hljs-comment">// 200</span>
|
|
453
|
+
|
|
454
|
+
<span class="hljs-keyword">await</span> mock.<span class="hljs-title function_">close</span>();
|
|
455
|
+
</code></pre>
|
|
456
|
+
<p>By default, HTTP/1.1 clients can still connect via ALPN negotiation (<code>http1</code> defaults to <code>true</code>). To disable HTTP/1.1 fallback:</p>
|
|
457
|
+
<pre><code class="hljs language-javascript"><span class="hljs-keyword">const</span> mock = <span class="hljs-keyword">new</span> <span class="hljs-title class_">MockHttp</span>({ <span class="hljs-attr">http2</span>: <span class="hljs-literal">true</span>, <span class="hljs-attr">https</span>: <span class="hljs-literal">true</span>, <span class="hljs-attr">http1</span>: <span class="hljs-literal">false</span> });
|
|
458
|
+
<span class="hljs-keyword">await</span> mock.<span class="hljs-title function_">start</span>();
|
|
459
|
+
</code></pre>
|
|
460
|
+
<h2 id="http2-cleartext-h2c">HTTP/2 Cleartext (h2c)</h2>
|
|
461
|
+
<pre><code class="hljs language-javascript"><span class="hljs-keyword">const</span> mock = <span class="hljs-keyword">new</span> <span class="hljs-title class_">MockHttp</span>({ <span class="hljs-attr">http2</span>: <span class="hljs-literal">true</span> });
|
|
462
|
+
<span class="hljs-keyword">await</span> mock.<span class="hljs-title function_">start</span>();
|
|
463
|
+
|
|
464
|
+
<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(mock.<span class="hljs-property">http2</span>); <span class="hljs-comment">// true</span>
|
|
465
|
+
|
|
466
|
+
<span class="hljs-keyword">await</span> mock.<span class="hljs-title function_">close</span>();
|
|
467
|
+
</code></pre>
|
|
468
|
+
<blockquote>
|
|
469
|
+
<p><strong>Note:</strong> Browsers do not support h2c. This mode is useful for testing gRPC or service-to-service communication.</p>
|
|
470
|
+
</blockquote>
|
|
471
|
+
<h2 id="http2-via-environment-variable">HTTP/2 via Environment Variable</h2>
|
|
472
|
+
<pre><code class="hljs language-bash">HTTP2=<span class="hljs-literal">true</span> node your-app.js
|
|
473
|
+
</code></pre>
|
|
474
|
+
</main>
|
|
475
|
+
<aside class="content-aside">
|
|
476
|
+
<h2 class="content-aside__title">TABLE OF CONTENTS</h2>
|
|
477
|
+
<ul class="content-aside__list" id="toc-list">
|
|
478
|
+
</ul>
|
|
479
|
+
</aside>
|
|
480
|
+
</div>
|
|
481
|
+
<a class="article__edit-link" href="https://github.com/jaredwray/mockhttp/edit/main/site/docs/https.md" target="_blank" rel="noopener noreferrer">
|
|
482
|
+
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M17 3a2.85 2.83 0 1 1 4 4L7.5 20.5 2 22l1.5-5.5Z"/><path d="m15 5 4 4"/></svg>
|
|
483
|
+
Edit this page
|
|
484
|
+
</a>
|
|
485
|
+
</article>
|
|
486
|
+
</div>
|
|
487
|
+
<footer>
|
|
488
|
+
<a href="/llms.txt" class="footer__link">llms.txt</a>
|
|
489
|
+
<a href="/feed.xml" class="footer__link" aria-label="RSS Feed">
|
|
490
|
+
<svg class="footer__icon" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor"><circle cx="6.18" cy="17.82" r="2.18"/><path d="M4 4.44v2.83c7.03 0 12.73 5.7 12.73 12.73h2.83c0-8.59-6.97-15.56-15.56-15.56zm0 5.66v2.83c3.9 0 7.07 3.17 7.07 7.07h2.83c0-5.47-4.43-9.9-9.9-9.9z"/></svg>
|
|
491
|
+
</a>
|
|
492
|
+
|
|
493
|
+
<a href="https://docula.org/" target="_blank" rel="noopener noreferrer" class="footer__link" aria-label="Docula">
|
|
494
|
+
<svg class="footer__bat" xmlns="http://www.w3.org/2000/svg" viewBox="70 110 360 205" fill="currentColor"><path d="M420,173c-16.76-18-72.78-36.65-131.59-30.58A160.15,160.15,0,0,0,269,120.55c-3.78,4.52-11.15,9.45-19,9.45s-15.23-4.93-19-9.45a160.15,160.15,0,0,0-19.4,21.83C152.78,136.31,96.76,154.94,80,173c48.86,5.86,79.5,34.09,79.5,72.06,52.37,0,77,28,90.5,59.94C263.54,273,288.13,245,340.5,245,340.5,207,371.14,178.8,420,173Z"/><circle cx="239.19" cy="145.36" r="3.32" fill="#fff"/><circle cx="260.81" cy="145.36" r="3.32" fill="#fff"/></svg>
|
|
495
|
+
</a>
|
|
496
|
+
<span class="footer__updated">updated: 2026-09-18</span>
|
|
497
|
+
</footer>
|
|
498
|
+
<script src="/css/highlight/highlight.min.js"></script>
|
|
499
|
+
<script>
|
|
500
|
+
document.addEventListener('DOMContentLoaded', () => {
|
|
501
|
+
document.querySelectorAll('pre code').forEach(el => { el.textContent = el.textContent.trimEnd(); });
|
|
502
|
+
hljs.highlightAll();
|
|
503
|
+
var kbd = document.querySelector('.search-button__shortcut');
|
|
504
|
+
if (kbd) kbd.textContent = navigator.platform.indexOf('Mac') > -1 ? '⌘K' : 'Ctrl K';
|
|
505
|
+
|
|
506
|
+
// Copy code buttons
|
|
507
|
+
const copyIcon = '<svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="9" y="9" width="13" height="13" rx="2" ry="2"/><path d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"/></svg>';
|
|
508
|
+
const checkIcon = '<svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="20 6 9 17 4 12"/></svg>';
|
|
509
|
+
document.querySelectorAll('pre').forEach(function(pre) {
|
|
510
|
+
const btn = document.createElement('button');
|
|
511
|
+
btn.className = 'copy-code-btn';
|
|
512
|
+
btn.innerHTML = copyIcon;
|
|
513
|
+
btn.setAttribute('aria-label', 'Copy code');
|
|
514
|
+
btn.addEventListener('click', function() {
|
|
515
|
+
const code = pre.querySelector('code');
|
|
516
|
+
const text = code ? code.textContent : pre.textContent;
|
|
517
|
+
navigator.clipboard.writeText(text || '').then(function() {
|
|
518
|
+
btn.innerHTML = checkIcon;
|
|
519
|
+
setTimeout(function() { btn.innerHTML = copyIcon; }, 2000);
|
|
520
|
+
});
|
|
521
|
+
});
|
|
522
|
+
pre.appendChild(btn);
|
|
523
|
+
});
|
|
524
|
+
});
|
|
525
|
+
</script>
|
|
526
|
+
<script>
|
|
527
|
+
(function() {
|
|
528
|
+
var themeKey = window.__doculaThemeKey;
|
|
529
|
+
function getMode() {
|
|
530
|
+
return localStorage.getItem(themeKey) || 'light';
|
|
531
|
+
}
|
|
532
|
+
|
|
533
|
+
function resolveTheme(mode) {
|
|
534
|
+
if (mode === 'system') {
|
|
535
|
+
return window.matchMedia('(prefers-color-scheme: light)').matches ? 'light' : 'dark';
|
|
536
|
+
}
|
|
537
|
+
return mode;
|
|
538
|
+
}
|
|
539
|
+
|
|
540
|
+
var cachedEls = null;
|
|
541
|
+
function getThemeEls() {
|
|
542
|
+
if (!cachedEls) {
|
|
543
|
+
cachedEls = {
|
|
544
|
+
systemIcon: document.querySelector('.theme-button__icon--system'),
|
|
545
|
+
sunIcon: document.querySelector('.theme-button__icon--sun'),
|
|
546
|
+
moonIcon: document.querySelector('.theme-button__icon--moon'),
|
|
547
|
+
toggle: document.getElementById('theme-toggle')
|
|
548
|
+
};
|
|
549
|
+
}
|
|
550
|
+
return cachedEls;
|
|
551
|
+
}
|
|
552
|
+
|
|
553
|
+
function applyTheme(mode) {
|
|
554
|
+
var resolved = resolveTheme(mode);
|
|
555
|
+
if (resolved === 'light') {
|
|
556
|
+
document.documentElement.setAttribute('data-theme', 'light');
|
|
557
|
+
} else {
|
|
558
|
+
document.documentElement.removeAttribute('data-theme');
|
|
559
|
+
}
|
|
560
|
+
|
|
561
|
+
var els = getThemeEls();
|
|
562
|
+
if (els.systemIcon && els.sunIcon && els.moonIcon) {
|
|
563
|
+
els.systemIcon.classList.add('theme-button__icon--hidden');
|
|
564
|
+
els.sunIcon.classList.add('theme-button__icon--hidden');
|
|
565
|
+
els.moonIcon.classList.add('theme-button__icon--hidden');
|
|
566
|
+
if (mode === 'system') {
|
|
567
|
+
els.systemIcon.classList.remove('theme-button__icon--hidden');
|
|
568
|
+
} else if (mode === 'light') {
|
|
569
|
+
els.sunIcon.classList.remove('theme-button__icon--hidden');
|
|
570
|
+
} else {
|
|
571
|
+
els.moonIcon.classList.remove('theme-button__icon--hidden');
|
|
572
|
+
}
|
|
573
|
+
}
|
|
574
|
+
|
|
575
|
+
if (els.toggle) {
|
|
576
|
+
var labels = { system: 'Theme: system (following system)', light: 'Theme: light', dark: 'Theme: dark' };
|
|
577
|
+
els.toggle.setAttribute('aria-label', labels[mode] || 'Toggle theme');
|
|
578
|
+
}
|
|
579
|
+
}
|
|
580
|
+
|
|
581
|
+
function nextMode(current) {
|
|
582
|
+
var cycle = { system: 'light', light: 'dark', dark: 'system' };
|
|
583
|
+
return cycle[current] || 'system';
|
|
584
|
+
}
|
|
585
|
+
|
|
586
|
+
var currentMode = getMode();
|
|
587
|
+
|
|
588
|
+
document.addEventListener('DOMContentLoaded', function() {
|
|
589
|
+
applyTheme(currentMode);
|
|
590
|
+
|
|
591
|
+
var els = getThemeEls();
|
|
592
|
+
if (els.toggle) {
|
|
593
|
+
els.toggle.addEventListener('click', function() {
|
|
594
|
+
currentMode = nextMode(currentMode);
|
|
595
|
+
localStorage.setItem(themeKey, currentMode);
|
|
596
|
+
applyTheme(currentMode);
|
|
597
|
+
});
|
|
598
|
+
}
|
|
599
|
+
});
|
|
600
|
+
|
|
601
|
+
window.matchMedia('(prefers-color-scheme: light)').addEventListener('change', function() {
|
|
602
|
+
if (getMode() === 'system') {
|
|
603
|
+
applyTheme('system');
|
|
604
|
+
}
|
|
605
|
+
});
|
|
606
|
+
})();
|
|
607
|
+
</script>
|
|
608
|
+
<script defer>
|
|
609
|
+
document.addEventListener('DOMContentLoaded', () => {
|
|
610
|
+
const menuToggle = document.getElementById('mobile-menu-toggle');
|
|
611
|
+
const mobileSidebar = document.getElementById('mobile-sidebar');
|
|
612
|
+
const backdrop = document.getElementById('sidebar-backdrop');
|
|
613
|
+
if (menuToggle && mobileSidebar) {
|
|
614
|
+
menuToggle.addEventListener('click', () => {
|
|
615
|
+
mobileSidebar.classList.toggle('mobile-sidebar--open');
|
|
616
|
+
if (backdrop) backdrop.classList.toggle('sidebar-backdrop--visible');
|
|
617
|
+
});
|
|
618
|
+
if (backdrop) {
|
|
619
|
+
backdrop.addEventListener('click', () => {
|
|
620
|
+
mobileSidebar.classList.remove('mobile-sidebar--open');
|
|
621
|
+
backdrop.classList.remove('sidebar-backdrop--visible');
|
|
622
|
+
});
|
|
623
|
+
}
|
|
624
|
+
}
|
|
625
|
+
|
|
626
|
+
// Page dropdown toggle (docs pages)
|
|
627
|
+
const dropdownToggle = document.getElementById('page-dropdown-toggle');
|
|
628
|
+
const dropdownList = document.getElementById('page-dropdown-list');
|
|
629
|
+
if (dropdownToggle && dropdownList) {
|
|
630
|
+
dropdownToggle.addEventListener('click', () => {
|
|
631
|
+
dropdownList.classList.toggle('page-dropdown__list--open');
|
|
632
|
+
});
|
|
633
|
+
}
|
|
634
|
+
|
|
635
|
+
// Active sidebar link highlighting
|
|
636
|
+
const sidebarLinks = document.querySelectorAll('.nav-sidebar__item');
|
|
637
|
+
const currentPath = window.location.pathname;
|
|
638
|
+
sidebarLinks.forEach((link) => {
|
|
639
|
+
if (link.getAttribute('href') === currentPath || link.getAttribute('href') === currentPath.replace(/\/$/, '')) {
|
|
640
|
+
link.classList.add('nav-sidebar__item--active');
|
|
641
|
+
}
|
|
642
|
+
});
|
|
643
|
+
|
|
644
|
+
// Sidebar section collapse/expand
|
|
645
|
+
const SIDEBAR_STORAGE_KEY = 'docula:sidebar-sections';
|
|
646
|
+
const collapsibleSections = document.querySelectorAll('.nav-sidebar__section--collapsible');
|
|
647
|
+
if (collapsibleSections.length > 0) {
|
|
648
|
+
let storedSectionState = {};
|
|
649
|
+
try {
|
|
650
|
+
storedSectionState = JSON.parse(localStorage.getItem(SIDEBAR_STORAGE_KEY) || '{}');
|
|
651
|
+
} catch (e) { storedSectionState = {}; }
|
|
652
|
+
|
|
653
|
+
const setSectionOpen = (section, toggle, open) => {
|
|
654
|
+
toggle.setAttribute('aria-expanded', open ? 'true' : 'false');
|
|
655
|
+
section.classList.toggle('nav-sidebar__section--collapsed', !open);
|
|
656
|
+
};
|
|
657
|
+
|
|
658
|
+
collapsibleSections.forEach((section, idx) => {
|
|
659
|
+
const toggle = section.querySelector('.nav-sidebar__toggle');
|
|
660
|
+
const list = section.querySelector('.nav-sidebar__list');
|
|
661
|
+
if (!toggle || !list) return;
|
|
662
|
+
const listId = 'nav-sidebar-section-' + idx;
|
|
663
|
+
list.id = listId;
|
|
664
|
+
toggle.setAttribute('aria-controls', listId);
|
|
665
|
+
|
|
666
|
+
const key = 'section-' + idx;
|
|
667
|
+
const hasStored = Object.prototype.hasOwnProperty.call(storedSectionState, key);
|
|
668
|
+
const isOpen = hasStored ? !!storedSectionState[key] : true;
|
|
669
|
+
setSectionOpen(section, toggle, isOpen);
|
|
670
|
+
|
|
671
|
+
toggle.addEventListener('click', () => {
|
|
672
|
+
const next = toggle.getAttribute('aria-expanded') !== 'true';
|
|
673
|
+
setSectionOpen(section, toggle, next);
|
|
674
|
+
storedSectionState[key] = next;
|
|
675
|
+
try {
|
|
676
|
+
localStorage.setItem(SIDEBAR_STORAGE_KEY, JSON.stringify(storedSectionState));
|
|
677
|
+
} catch (e) { /* storage unavailable */ }
|
|
678
|
+
});
|
|
679
|
+
});
|
|
680
|
+
}
|
|
681
|
+
|
|
682
|
+
// Active nav link highlighting (header + mobile). Highlight only the
|
|
683
|
+
// single most-specific link: the one whose path is the longest prefix of
|
|
684
|
+
// the current path. A plain startsWith() check lights up every link whose
|
|
685
|
+
// path merely prefixes the current one, so when the site is embedded under
|
|
686
|
+
// a base path (e.g. served at /developer with docs at that root) the
|
|
687
|
+
// Documentation link — whose path is a prefix of every page — would stay
|
|
688
|
+
// highlighted everywhere. Trailing slashes are normalized so matches stop
|
|
689
|
+
// at a path boundary. We read the anchor's resolved origin/pathname so
|
|
690
|
+
// absolute, relative, and same-origin hrefs all work, while cross-origin
|
|
691
|
+
// links and non-anchor items (e.g. the mobile logout button) are skipped.
|
|
692
|
+
const withTrailingSlash = (p) => (p.endsWith('/') ? p : p + '/');
|
|
693
|
+
const here = withTrailingSlash(currentPath);
|
|
694
|
+
const markActiveNav = (selector, activeClass) => {
|
|
695
|
+
let bestLink = null;
|
|
696
|
+
let bestLength = -1;
|
|
697
|
+
document.querySelectorAll(selector).forEach((link) => {
|
|
698
|
+
// Only same-origin anchors can match the current pathname.
|
|
699
|
+
if (!link.href || link.origin !== window.location.origin) return;
|
|
700
|
+
const base = withTrailingSlash(link.pathname);
|
|
701
|
+
if (here.startsWith(base) && base.length > bestLength) {
|
|
702
|
+
bestLink = link;
|
|
703
|
+
bestLength = base.length;
|
|
704
|
+
}
|
|
705
|
+
});
|
|
706
|
+
if (bestLink) bestLink.classList.add(activeClass);
|
|
707
|
+
};
|
|
708
|
+
markActiveNav('.header-bottom__item', 'header-bottom__item--active');
|
|
709
|
+
markActiveNav('.mobile-nav__item', 'mobile-nav__item--active');
|
|
710
|
+
|
|
711
|
+
// TOC extraction: move the inline TOC into the right sidebar and hide the original
|
|
712
|
+
const tocHeading = document.getElementById('table-of-contents');
|
|
713
|
+
if (tocHeading) {
|
|
714
|
+
const tocList = tocHeading.nextElementSibling;
|
|
715
|
+
const tocTarget = document.getElementById('toc-list');
|
|
716
|
+
if (tocList && tocList.tagName === 'UL' && tocTarget) {
|
|
717
|
+
tocTarget.innerHTML = tocList.innerHTML;
|
|
718
|
+
tocHeading.style.display = 'none';
|
|
719
|
+
tocList.style.display = 'none';
|
|
720
|
+
}
|
|
721
|
+
}
|
|
722
|
+
|
|
723
|
+
// Hide the TOC aside if it has no entries
|
|
724
|
+
const tocSidebar = document.getElementById('toc-list');
|
|
725
|
+
if (tocSidebar && tocSidebar.children.length === 0) {
|
|
726
|
+
const aside = tocSidebar.closest('.content-aside');
|
|
727
|
+
if (aside) { aside.style.display = 'none'; }
|
|
728
|
+
}
|
|
729
|
+
|
|
730
|
+
// Image lightbox
|
|
731
|
+
const lightboxOverlay = document.createElement('div');
|
|
732
|
+
lightboxOverlay.className = 'lightbox-overlay';
|
|
733
|
+
lightboxOverlay.addEventListener('click', function(e) {
|
|
734
|
+
if (e.target !== lightboxImg) lightboxOverlay.classList.remove('lightbox-overlay--visible');
|
|
735
|
+
});
|
|
736
|
+
const lightboxClose = document.createElement('button');
|
|
737
|
+
lightboxClose.className = 'lightbox-close';
|
|
738
|
+
lightboxClose.innerHTML = '<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><line x1="18" y1="6" x2="6" y2="18"/><line x1="6" y1="6" x2="18" y2="18"/></svg>';
|
|
739
|
+
lightboxClose.addEventListener('click', function() {
|
|
740
|
+
lightboxOverlay.classList.remove('lightbox-overlay--visible');
|
|
741
|
+
});
|
|
742
|
+
const lightboxImg = document.createElement('img');
|
|
743
|
+
lightboxOverlay.appendChild(lightboxClose);
|
|
744
|
+
lightboxOverlay.appendChild(lightboxImg);
|
|
745
|
+
document.body.appendChild(lightboxOverlay);
|
|
746
|
+
|
|
747
|
+
document.querySelectorAll('.article__main img, .changelog-entry-body img').forEach(function(img) {
|
|
748
|
+
if (img.closest('a')) return;
|
|
749
|
+
img.addEventListener('click', function() {
|
|
750
|
+
lightboxImg.src = img.src;
|
|
751
|
+
lightboxOverlay.classList.add('lightbox-overlay--visible');
|
|
752
|
+
});
|
|
753
|
+
});
|
|
754
|
+
});
|
|
755
|
+
</script>
|
|
756
|
+
</body>
|
|
757
|
+
|
|
758
|
+
</html>
|