()
| 751 | } |
| 752 | |
| 753 | func (app *App) ensureAutoHeadRoutesLocked() { |
| 754 | if app.config.DisableHeadAutoRegister { |
| 755 | return |
| 756 | } |
| 757 | |
| 758 | headIndex := app.methodInt(MethodHead) |
| 759 | getIndex := app.methodInt(MethodGet) |
| 760 | if headIndex == -1 || getIndex == -1 { |
| 761 | return |
| 762 | } |
| 763 | |
| 764 | headStack := app.stack[headIndex] |
| 765 | existing := make(map[string]struct{}, len(headStack)) |
| 766 | for _, route := range headStack { |
| 767 | if route.mount || route.use { |
| 768 | continue |
| 769 | } |
| 770 | existing[route.path] = struct{}{} |
| 771 | } |
| 772 | |
| 773 | if len(app.stack[getIndex]) == 0 { |
| 774 | return |
| 775 | } |
| 776 | |
| 777 | var added bool |
| 778 | |
| 779 | for _, route := range app.stack[getIndex] { |
| 780 | if route.mount || route.use { |
| 781 | continue |
| 782 | } |
| 783 | if _, ok := existing[route.path]; ok { |
| 784 | continue |
| 785 | } |
| 786 | |
| 787 | headRoute := app.copyRoute(route) |
| 788 | headRoute.group = route.group |
| 789 | headRoute.Method = MethodHead |
| 790 | headRoute.autoHead = true |
| 791 | // Fasthttp automatically omits response bodies when transmitting |
| 792 | // HEAD responses, so the copied GET handler stack can execute |
| 793 | // unchanged while still producing an empty body on the wire. |
| 794 | |
| 795 | headStack = append(headStack, headRoute) |
| 796 | existing[route.path] = struct{}{} |
| 797 | app.hasRoutesRefreshed = true |
| 798 | added = true |
| 799 | |
| 800 | atomic.AddUint32(&app.handlersCount, uint32(len(headRoute.Handlers))) //nolint:gosec // G115 - handler count is always small |
| 801 | |
| 802 | app.latestRoute = headRoute |
| 803 | if err := app.hooks.executeOnRouteHooks(headRoute); err != nil { |
| 804 | panic(err) |
| 805 | } |
| 806 | } |
| 807 | |
| 808 | if added { |
| 809 | app.stack[headIndex] = headStack |
| 810 | } |
no test coverage detected