X-Forwarded-Proto is an HTTP Header and is part of the HTTP standard.
It is set on each HTTP request by a proxy or load balancer and can be used by a server application to determine what protocol the client used to connect.
To understand X-Forwarded-Proto you have to understand the normal flow of communication when a client makes an HTTP request to a HTTPS-only resource.
Note: Proxy in this example refers to HAProxy or any other proxy or load balancer that decrypts HTTPS traffic before it reaches an application.
This is a simple example with direct communication between the client and server:
What happens when there is a proxy device that decrypts the traffic?
How does X-Forwarded-Proto prevent a redirect loop?
In step 6 above, the Proxy is setting the HTTP header "X-Forwarded-Proto: https" to specify that the traffic it received is HTTPS. In step 8, the Server then uses the X-Forwarded-Proto to determine if the request was HTTP or HTTPS.
For more information about the X-Forwarded-Proto HTTP header, refer to: