Created
April 30, 2012 18:40
-
-
Save iggymacd/2560952 to your computer and use it in GitHub Desktop.
Sample NotFound Handler
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
class NotFoundHandler { | |
NotFoundHandler(){ | |
} | |
List<int> _notFoundPage; | |
static final String notFoundPageHtml = """ | |
<html><head> | |
<title>404 Not Found</title> | |
</head><body> | |
<h1>Not Found</h1> | |
<p>The requested URL was not found on this server.</p> | |
</body></html>"""; | |
void onRequest(HttpRequest request, HttpResponse response){ | |
if (_notFoundPage == null) { | |
_notFoundPage = notFoundPageHtml.charCodes(); | |
} | |
response.statusCode = HttpStatus.NOT_FOUND; | |
response.headers.set("Content-Type", "text/html; charset=UTF-8"); | |
response.contentLength = _notFoundPage.length; | |
response.outputStream.write(_notFoundPage); | |
response.outputStream.close(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment