MCPcopy Create free account
hub / github.com/kataras/iris / GetReferrer

Method GetReferrer

context/context.go:1290–1325  ·  view source on GitHub ↗

GetReferrer extracts and returns the information from the "Referer" (or "Referrer") header and url query parameter as specified in https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Referrer-Policy.

()

Source from the content-addressed store, hash-verified

1288// GetReferrer extracts and returns the information from the "Referer" (or "Referrer") header
1289// and url query parameter as specified in https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Referrer-Policy.
1290func (ctx *Context) GetReferrer() Referrer {
1291 // the underline net/http follows the https://tools.ietf.org/html/rfc7231#section-5.5.2,
1292 // so there is nothing special left to do.
1293 // https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Referrer-Policy
1294 refURL := ctx.GetHeader("Referer")
1295 if refURL == "" {
1296 refURL = ctx.GetHeader("Referrer")
1297 if refURL == "" {
1298 refURL = ctx.URLParam("referer")
1299 if refURL == "" {
1300 refURL = ctx.URLParam("referrer")
1301 }
1302 }
1303 }
1304
1305 if refURL == "" {
1306 return emptyReferrer
1307 }
1308
1309 if ref := goreferrer.DefaultRules.Parse(refURL); ref.Type > goreferrer.Invalid {
1310 return Referrer{
1311 Raw: refURL,
1312 Type: ReferrerType(ref.Type),
1313 Label: ref.Label,
1314 URL: ref.URL,
1315 Subdomain: ref.Subdomain,
1316 Domain: ref.Domain,
1317 Tld: ref.Tld,
1318 Path: ref.Path,
1319 Query: ref.Query,
1320 GoogleType: ReferrerGoogleSearchType(ref.GoogleType),
1321 }
1322 }
1323
1324 return emptyReferrer
1325}
1326
1327// SetLanguage force-sets the language for i18n, can be used inside a middleare.
1328// It has the highest priority over the rest and if it is empty then it is ignored,

Callers 1

mainFunction · 0.80

Calls 3

GetHeaderMethod · 0.95
URLParamMethod · 0.95
ParseMethod · 0.65

Tested by

no test coverage detected