1
0
mirror of https://github.com/gofiber/fiber.git synced 2025-02-24 14:23:55 +00:00
Roman 5a3edb9011 🔥add the option to set a custom Cache-Control value for a favicon response
Right now, each favicon response sets the `Cache-Control` header to
`public, max-age=31536000` (1 year). In some cases this could be a
little bit high if you are changing it etc. and the header is not
replaced by a reverse proxy.

With this change, the favicon middleware allows the configuration of the
`Cache-Control` header. The default behavior is to keep the setting of
`max-age=31536000 `, but you could fine-tune it.
2020-10-05 08:35:29 +02:00
..
v2
2020-09-13 11:20:11 +02:00

Favicon Authentication

Favicon middleware for Fiber that ignores favicon requests or caches a provided icon in memory to improve performance by skipping disk access. User agents request favicon.ico frequently and indiscriminately, so you may wish to exclude these requests from your logs by using this middleware before your logger middleware.

Note This middleware is exclusively for serving the default, implicit favicon, which is GET /favicon.ico.

Table of Contents

Signatures

func New(config ...Config) fiber.Handler

Examples

Import the middleware package that is part of the Fiber web framework

import (
  "github.com/gofiber/fiber/v2"
  "github.com/gofiber/fiber/v2/middleware/favicon"
)

After you initiate your Fiber app, you can use the following possibilities:

// Provide a minimal config
app.Use(favicon.New())

// Or extend your config for customization
app.Use(favicon.New(favicon.Config{
	File: "./favicon.ico"
}))

Config

// Config defines the config for middleware.
type Config struct {
	// Next defines a function to skip this middleware when returned true.
	//
	// Optional. Default: nil
	Next func(c *fiber.Ctx) bool

	// File holds the path to an actual favicon that will be cached
	//
	// Optional. Default: ""
	File string
}

Default Config

var ConfigDefault = Config{
	Next: nil,
	File:	""
}