Repository: caddyserver/caddy
File: modules/caddyhttp/reverseproxy/httptransport.go (Go)

Code before:
				address = dialInfo.Address
			}
		}

		conn, err := dialer.DialContext(ctx, network, address)
		if err != nil {
			// identify this error as one that occurred during
			// dialing, which can be important when trying to
			// decide whether to retry a request
			return nil, DialError{err}
		}

		if h.ProxyProtocol != "" {
			proxyProtocolInfo, ok := caddyhttp.GetVar(ctx, proxyProtocolInfoVarKey).(ProxyProtocolInfo)
			if !ok {
				return nil, fmt.Errorf("failed to get proxy protocol info from context")
			}
			header := proxyproto.Header{
				SourceAddr: &net.TCPAddr{
					IP:   proxyProtocolInfo.AddrPort.Addr().AsSlice(),
					Port: int(proxyProtocolInfo.AddrPort.Port()),
					Zone: proxyProtocolInfo.AddrPort.Addr().Zone(),
				},
			}
			// The src and dst have to be of the same address family. As we don't know the original
			// dst address (it's kind of impossible to know) and this address is generelly of very
			// little interest, we just set it to all zeros.
			switch {
			case proxyProtocolInfo.AddrPort.Addr().Is4():
				header.TransportProtocol = proxyproto.TCPv4
				header.DestinationAddr = &net.TCPAddr{
					IP: net.IPv4zero,
				}
			case proxyProtocolInfo.AddrPort.Addr().Is6():
				header.TransportProtocol = proxyproto.TCPv6
				header.DestinationAddr = &net.TCPAddr{
					IP: net.IPv6zero,
				}
			default:
				return nil, fmt.Errorf("unexpected remote addr type in proxy protocol info")
			}

			switch h.ProxyProtocol {
			case "v1":
				header.Version = 1
				caddyCtx.Logger().Debug("sending proxy protocol header v1", zap.Any("header", header))
			case "v2":
				header.Version = 2
				caddyCtx.Logger().Debug("sending proxy protocol header v2", zap.Any("header", header))
			default:
				return nil, fmt.Errorf("unexpected proxy protocol version")

Review comment (suggestion):
Noticed this typo (from before)

```suggestion
			// dst address (it's kind of impossible to know) and this address is generally of very
```

Code after:
				address = dialInfo.Address
			}
		}

		conn, err := dialer.DialContext(ctx, network, address)
		if err != nil {
			// identify this error as one that occurred during
			// dialing, which can be important when trying to
			// decide whether to retry a request
			return nil, DialError{err}
		}

		if h.ProxyProtocol != "" {
			proxyProtocolInfo, ok := caddyhttp.GetVar(ctx, proxyProtocolInfoVarKey).(ProxyProtocolInfo)
			if !ok {
				return nil, fmt.Errorf("failed to get proxy protocol info from context")
			}
			header := proxyproto.Header{
				SourceAddr: &net.TCPAddr{
					IP:   proxyProtocolInfo.AddrPort.Addr().AsSlice(),
					Port: int(proxyProtocolInfo.AddrPort.Port()),
					Zone: proxyProtocolInfo.AddrPort.Addr().Zone(),
				},
			}
			// The src and dst have to be of the same address family. As we don't know the original
			// dst address (it's kind of impossible to know) and this address is generally of very
			// little interest, we just set it to all zeros.
			switch {
			case proxyProtocolInfo.AddrPort.Addr().Is4():
				header.TransportProtocol = proxyproto.TCPv4
				header.DestinationAddr = &net.TCPAddr{
					IP: net.IPv4zero,
				}
			case proxyProtocolInfo.AddrPort.Addr().Is6():
				header.TransportProtocol = proxyproto.TCPv6
				header.DestinationAddr = &net.TCPAddr{
					IP: net.IPv6zero,
				}
			default:
				return nil, fmt.Errorf("unexpected remote addr type in proxy protocol info")
			}

			switch h.ProxyProtocol {
			case "v1":
				header.Version = 1
				caddyCtx.Logger().Debug("sending proxy protocol header v1", zap.Any("header", header))
			case "v2":
				header.Version = 2
				caddyCtx.Logger().Debug("sending proxy protocol header v2", zap.Any("header", header))
			default:
				return nil, fmt.Errorf("unexpected proxy protocol version")