@@ -60,8 +60,7 @@ public final class HAProxyMessageChannelHandler extends ChannelInboundHandlerAda
60
60
61
61
@ Override
62
62
public void channelRead (ChannelHandlerContext ctx , Object msg ) {
63
- if (msg instanceof HAProxyMessage ) {
64
- HAProxyMessage hapm = (HAProxyMessage ) msg ;
63
+ if (msg instanceof HAProxyMessage hapm ) {
65
64
Channel channel = ctx .channel ();
66
65
channel .attr (ATTR_HAPROXY_MESSAGE ).set (hapm );
67
66
ctx .channel ().closeFuture ().addListener ((ChannelFutureListener ) future -> hapm .release ());
@@ -85,32 +84,30 @@ private void parseSrcAddr(HAProxyMessage hapm, Channel channel) {
85
84
channel .attr (SourceAddressChannelHandler .ATTR_SOURCE_ADDRESS ).set (sourceAddress );
86
85
87
86
SocketAddress srcAddr ;
88
- out :
89
- {
90
- switch (hapm .proxiedProtocol ()) {
91
- case UNKNOWN :
92
- throw new IllegalArgumentException ("unknown proxy protocol" + sourceAddress );
93
- case TCP4 :
94
- case TCP6 :
95
- InetSocketAddress inetAddr ;
96
- srcAddr = inetAddr =
97
- new InetSocketAddress (InetAddresses .forString (sourceAddress ), hapm .sourcePort ());
98
- Attrs attrs = channel .attr (Server .CONN_DIMENSIONS ).get ();
99
- if (inetAddr .getAddress () instanceof Inet4Address ) {
100
- HAPM_SRC_IP_VERSION .put (attrs , "v4" );
101
- } else if (inetAddr .getAddress () instanceof Inet6Address ) {
102
- HAPM_SRC_IP_VERSION .put (attrs , "v6" );
103
- } else {
104
- HAPM_SRC_IP_VERSION .put (attrs , "unknown" );
105
- }
106
- break out ;
107
- case UNIX_STREAM : // TODO: implement
108
- case UDP4 :
109
- case UDP6 :
110
- case UNIX_DGRAM :
111
- throw new IllegalArgumentException ("unknown proxy protocol" + sourceAddress );
112
- }
113
- throw new AssertionError (hapm .proxiedProtocol ());
87
+ switch (hapm .proxiedProtocol ()) {
88
+ case UNKNOWN :
89
+ throw new IllegalArgumentException ("unknown proxy protocol" + sourceAddress );
90
+ case TCP4 :
91
+ case TCP6 :
92
+ InetSocketAddress inetAddr ;
93
+ srcAddr =
94
+ inetAddr = new InetSocketAddress (InetAddresses .forString (sourceAddress ), hapm .sourcePort ());
95
+ Attrs attrs = channel .attr (Server .CONN_DIMENSIONS ).get ();
96
+ if (inetAddr .getAddress () instanceof Inet4Address ) {
97
+ HAPM_SRC_IP_VERSION .put (attrs , "v4" );
98
+ } else if (inetAddr .getAddress () instanceof Inet6Address ) {
99
+ HAPM_SRC_IP_VERSION .put (attrs , "v6" );
100
+ } else {
101
+ HAPM_SRC_IP_VERSION .put (attrs , "unknown" );
102
+ }
103
+ break ;
104
+ case UNIX_STREAM : // TODO: implement
105
+ case UDP4 :
106
+ case UDP6 :
107
+ case UNIX_DGRAM :
108
+ throw new IllegalArgumentException ("unknown proxy protocol" + sourceAddress );
109
+ default :
110
+ throw new AssertionError (hapm .proxiedProtocol ());
114
111
}
115
112
channel .attr (SourceAddressChannelHandler .ATTR_REMOTE_ADDR ).set (srcAddr );
116
113
}
@@ -120,37 +117,36 @@ private void parseDstAddr(HAProxyMessage hapm, Channel channel) {
120
117
String destinationAddress = hapm .destinationAddress ();
121
118
if (destinationAddress != null ) {
122
119
channel .attr (SourceAddressChannelHandler .ATTR_LOCAL_ADDRESS ).set (destinationAddress );
120
+
123
121
SocketAddress dstAddr ;
124
- out :
125
- {
126
- switch (hapm .proxiedProtocol ()) {
127
- case UNKNOWN :
128
- throw new IllegalArgumentException ("unknown proxy protocol" + destinationAddress );
129
- case TCP4 :
130
- case TCP6 :
131
- InetSocketAddress inetAddr = new InetSocketAddress (
132
- InetAddresses .forString (destinationAddress ), hapm .destinationPort ());
133
- dstAddr = inetAddr ;
134
- // set ppv2 attr explicitly because ATTR_LOCAL_ADDR could be non ppv2
135
- channel .attr (SourceAddressChannelHandler .ATTR_PROXY_PROTOCOL_DESTINATION_ADDRESS )
136
- .set (inetAddr );
137
- Attrs attrs = channel .attr (Server .CONN_DIMENSIONS ).get ();
138
- if (inetAddr .getAddress () instanceof Inet4Address ) {
139
- HAPM_DEST_IP_VERSION .put (attrs , "v4" );
140
- } else if (inetAddr .getAddress () instanceof Inet6Address ) {
141
- HAPM_DEST_IP_VERSION .put (attrs , "v6" );
142
- } else {
143
- HAPM_DEST_IP_VERSION .put (attrs , "unknown" );
144
- }
145
- HAPM_DEST_PORT .put (attrs , hapm .destinationPort ());
146
- break out ;
147
- case UNIX_STREAM : // TODO: implement
148
- case UDP4 :
149
- case UDP6 :
150
- case UNIX_DGRAM :
151
- throw new IllegalArgumentException ("unknown proxy protocol" + destinationAddress );
152
- }
153
- throw new AssertionError (hapm .proxiedProtocol ());
122
+ switch (hapm .proxiedProtocol ()) {
123
+ case UNKNOWN :
124
+ throw new IllegalArgumentException ("unknown proxy protocol" + destinationAddress );
125
+ case TCP4 :
126
+ case TCP6 :
127
+ InetSocketAddress inetAddr =
128
+ new InetSocketAddress (InetAddresses .forString (destinationAddress ), hapm .destinationPort ());
129
+ dstAddr = inetAddr ;
130
+ // set ppv2 attr explicitly because ATTR_LOCAL_ADDR could be non ppv2
131
+ channel .attr (SourceAddressChannelHandler .ATTR_PROXY_PROTOCOL_DESTINATION_ADDRESS )
132
+ .set (inetAddr );
133
+ Attrs attrs = channel .attr (Server .CONN_DIMENSIONS ).get ();
134
+ if (inetAddr .getAddress () instanceof Inet4Address ) {
135
+ HAPM_DEST_IP_VERSION .put (attrs , "v4" );
136
+ } else if (inetAddr .getAddress () instanceof Inet6Address ) {
137
+ HAPM_DEST_IP_VERSION .put (attrs , "v6" );
138
+ } else {
139
+ HAPM_DEST_IP_VERSION .put (attrs , "unknown" );
140
+ }
141
+ HAPM_DEST_PORT .put (attrs , hapm .destinationPort ());
142
+ break ;
143
+ case UNIX_STREAM : // TODO: implement
144
+ case UDP4 :
145
+ case UDP6 :
146
+ case UNIX_DGRAM :
147
+ throw new IllegalArgumentException ("unknown proxy protocol" + destinationAddress );
148
+ default :
149
+ throw new AssertionError (hapm .proxiedProtocol ());
154
150
}
155
151
channel .attr (SourceAddressChannelHandler .ATTR_LOCAL_ADDR ).set (dstAddr );
156
152
}
0 commit comments