Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add pages to simulate HTTP and WebView errors #209

Merged
merged 3 commits into from
May 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
Loading