Skip to content

Instantly share code, notes, and snippets.

@hhariri
Last active December 20, 2015 18:29
Show Gist options
  • Save hhariri/6176211 to your computer and use it in GitHub Desktop.
Save hhariri/6176211 to your computer and use it in GitHub Desktop.
// implementation of favicon interceptor
public class FavIconInterceptor(val icon: String): Interceptor {
override fun intercept(request: Request, response: Response): Boolean {
if (request.method == HttpMethod.GET && request.uri.compareToIgnoreCase("/favicon.ico") == 0) {
response.streamFile(icon, "image/x-icon")
return true
}
return false
}
}
// optional extension method for easier usage
fun AppServer.favicon(icon: String) {
intercept(FavIconInterceptor(icon))
}
// usage
val server = AppServer()
server.favicon("/public/icon.ico")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment