Last active
December 20, 2015 18:29
-
-
Save hhariri/6176211 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// 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