@@ -142,6 +142,26 @@ function collapseLeadingSlashes (str) {
142142 : str
143143}
144144
145+ /**
146+ * Create a minimal HTML document.
147+ *
148+ * @param {string } title
149+ * @param {string } body
150+ * @private
151+ */
152+
153+ function createHtmlDocument ( title , body ) {
154+ return '<!DOCTYPE html>\n' +
155+ '<html lang="en">\n' +
156+ '<head>\n' +
157+ '<meta charset="utf-8">\n' +
158+ '<title>' + title + '</title>\n' +
159+ '</head>\n' +
160+ '<body>\n' +
161+ '<pre>' + body + '</pre>\n' +
162+ '</body>\n'
163+ }
164+
145165/**
146166 * Create a directory listener that just 404s.
147167 * @private
@@ -174,16 +194,17 @@ function createRedirectDirectoryListener () {
174194
175195 // reformat the URL
176196 var loc = encodeUrl ( url . format ( originalUrl ) )
177- var msg = 'Redirecting to <a href="' + escapeHtml ( loc ) + '">' + escapeHtml ( loc ) + '</a>\n'
197+ var doc = createHtmlDocument ( 'Redirecting' , 'Redirecting to <a href="' + escapeHtml ( loc ) + '">' +
198+ escapeHtml ( loc ) + '</a>' )
178199 var res = this . res
179200
180201 // send redirect response
181202 res . statusCode = 301
182203 res . setHeader ( 'Content-Type' , 'text/html; charset=UTF-8' )
183- res . setHeader ( 'Content-Length' , Buffer . byteLength ( msg ) )
204+ res . setHeader ( 'Content-Length' , Buffer . byteLength ( doc ) )
184205 res . setHeader ( 'Content-Security-Policy' , "default-src 'self'" )
185206 res . setHeader ( 'X-Content-Type-Options' , 'nosniff' )
186207 res . setHeader ( 'Location' , loc )
187- res . end ( msg )
208+ res . end ( doc )
188209 }
189210}
0 commit comments