Skip to content

Commit

Permalink
Add pages to simulate HTTP and WebView errors (#209)
Browse files Browse the repository at this point in the history
* Add pages to simulate HTTP/WebView errors

* lint

* code review
  • Loading branch information
nshuba authored May 28, 2024
1 parent 84a24d0 commit 82d8af7
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 0 deletions.
1 change: 1 addition & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ <h2>Browser Features</h2>
<li><a href="./features/element-hiding/">Element Hiding</a></li>
<li><a href="./features/auto-refresh.html">Auto Refresh</a></li>
<li><a href="./features/favicon/">Favicon</a></li>
<li><a href="./network-error/">Network Errors</a></li>
</ul>

<h2>Security</h2>
Expand Down
31 changes: 31 additions & 0 deletions network-error/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Network Errors Tests</title>
</head>
<body>
<p><a href="../../">[Home]</a><strong>[Network Error Tests]</strong></p>

<p>This page allows testing various HTTP statuses and network errors.</p>
<p>To test an HTTP status, simply pass it as a query param: <code>/network-error/http_status/?code=404</code></p>
<p>Examples below:</p>

<ul>
<li>
<a href="http_status/?code=401">401 Unauthorized</a>
- will also set the <code>WWW-Authenticate Response</code> header
</li>
<li><a href="http_status/?code=404">404 Not Found</a></li>
<li><a href="http_status/?code=500">500 Internal Server Error</a></li>
</ul>

<p>Available network errors:</p>

<ul>
<li><a href="drop">Connection drop</a></li>
</ul>

</body>
</html>
28 changes: 28 additions & 0 deletions network-error/server/routes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
const express = require('express');
const router = express.Router();

// Simulate HTTP errors
router.get('/http_status/', (req, res) => {
const code = parseInt(req.query.code);

if (code === 401) {
// This sets a WebView error on Windows
res.set('WWW-Authenticate', 'Basic realm="Restricted Area"');
}

if (isNaN(code) || code < 100 || code > 599) {
res.statusCode = 200;
res.send('Invalid HTTP error code provided. Status not set.');
} else {
res.statusCode = code;
res.send(`HTTP error code set to '${code}'`);
}
res.end();
});

// Simulate connection drop
router.get('/drop', (_, res) => {
res.destroy();
});

module.exports = router;
3 changes: 3 additions & 0 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -286,3 +286,6 @@ app.use('/viewport', viewportRoutes);

const addressBarSpoofingRoutes = require('./security/address-bar-spoofing/server/routes.js');
app.use('/security/address-bar-spoofing-download-redirect', addressBarSpoofingRoutes);

const networkErrorRoutes = require('./network-error/server/routes.js');
app.use('/network-error', networkErrorRoutes);

0 comments on commit 82d8af7

Please sign in to comment.