-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add pages to simulate HTTP and WebView errors (#209)
* Add pages to simulate HTTP/WebView errors * lint * code review
- Loading branch information
Showing
4 changed files
with
63 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters