Skip to content

Instantly share code, notes, and snippets.

@adam-singer
Forked from iggymacd/NotFoundHandler.dart
Created May 1, 2012 02:34
Show Gist options
  • Save adam-singer/2564562 to your computer and use it in GitHub Desktop.
Save adam-singer/2564562 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