MCPcopy
hub / github.com/github/docs / usePermanentRedirect

Function usePermanentRedirect

middleware/redirects/handle-redirects.js:170–187  ·  view source on GitHub ↗
(req)

Source from the content-addressed store, hash-verified

168}
169
170function usePermanentRedirect(req) {
171 // If the redirect was to essentially swap `enterprise-server@latest`
172 // for `enterprise-server@3.x` then, we definitely don't want to
173 // do a permanent redirect.
174 // When this is the case, we don't want a permanent redirect because
175 // it could overzealously cache in the users' browser which could
176 // be bad when whatever "latest" means changes.
177 if (req.path.includes('/enterprise-server@latest')) return false
178
179 // If the redirect involved injecting a language prefix, then don't
180 // permanently redirect because that could overly cache in users'
181 // browsers if we some day want to make the language redirect
182 // depend on a cookie or 'Accept-Language' header.
183 if (pathLanguagePrefixed(req.path)) return true
184
185 // The default is to *not* do a permanent redirect.
186 return false
187}
188
189function removeQueryParams(redirect) {
190 return new URL(redirect, 'https://docs.github.com').pathname

Callers 1

handleRedirectsFunction · 0.85

Calls 1

pathLanguagePrefixedFunction · 0.90

Tested by

no test coverage detected