Home / Function/ normalizeOrigin() — fiber Function Reference

normalizeOrigin() — fiber Function Reference

Architecture documentation for the normalizeOrigin() function in utils.go from the fiber codebase.

Entity Profile

Dependency Diagram

graph TD
  e4978aa8_f324_a09f_5367_e46e192fa733["normalizeOrigin()"]
  5f252b75_33b5_0425_0ab1_e1b45c8382fe["utils.go"]
  e4978aa8_f324_a09f_5367_e46e192fa733 -->|defined in| 5f252b75_33b5_0425_0ab1_e1b45c8382fe
  style e4978aa8_f324_a09f_5367_e46e192fa733 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

middleware/cors/utils.go lines 40–66

func normalizeOrigin(origin string) (valid bool, normalized string) { //nolint:nonamedreturns // gocritic unnamedResult prefers naming validity and normalized origin results
	parsedOrigin, err := url.Parse(origin)
	if err != nil {
		return false, ""
	}

	// Don't allow a wildcard with a protocol
	// wildcards cannot be used within any other value. For example, the following header is not valid:
	// Access-Control-Allow-Origin: https://*
	if strings.IndexByte(parsedOrigin.Host, '*') >= 0 {
		return false, ""
	}

	// Validate there is a host present. The presence of a path, query, or fragment components
	// is checked, but a trailing "/" (indicative of the root) is allowed for the path and will be normalized
	if parsedOrigin.User != nil ||
		parsedOrigin.Host == "" ||
		(parsedOrigin.Path != "" && parsedOrigin.Path != "/") ||
		parsedOrigin.RawQuery != "" ||
		parsedOrigin.Fragment != "" {
		return false, ""
	}

	// Normalize the origin by constructing it from the scheme and host.
	// The path or trailing slash is not included in the normalized origin.
	return true, utils.ToLower(parsedOrigin.Scheme) + "://" + utils.ToLower(parsedOrigin.Host)
}

Domain

Subdomains

Frequently Asked Questions

What does normalizeOrigin() do?
normalizeOrigin() is a function in the fiber codebase, defined in middleware/cors/utils.go.
Where is normalizeOrigin() defined?
normalizeOrigin() is defined in middleware/cors/utils.go at line 40.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free