Skip to content

Instantly share code, notes, and snippets.

@iggymacd
Created April 30, 2012 18:40
Show Gist options
  • Save iggymacd/2560952 to your computer and use it in GitHub Desktop.
Save iggymacd/2560952 to your computer and use it in GitHub Desktop.
Sample NotFound Handler
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