Setting content-type on response

8 views
Skip to first unread message

Jon Kleiser

unread,
Sep 16, 2015, 5:25:00 AM9/16/15
to Redstone.dart
I'm doing a small server based on the code in http://dart.academy/easy-custom-web-servers-with-dart-and-redstone/. In my server I want one (or more) html page to be generated dynamically. I've found out that one way to set the proper content-type on the response, is to use an Interceptor like this:

@app.Interceptor(r"^\/.+\.html$")
htmlContent() {
  app.chain.next(() {
    app.response = app.response.change(headers: {"content-type": "text/html"});
  });
}

Are there simpler or better ways to do it?

Could I also use this Interceptor to set the charset="utf-8"?

The reg.ex I picked, one that matches any path "/foo.html", of course also matches paths for static pages like "/index.html", but that doesn't seem to be a problem.
Reply all
Reply to author
Forward
0 new messages