Skip to content

Commit c73e8bb

Browse files
committed
Context.getRemoteAddress() not returning IP address fix #1371
1 parent e1d5565 commit c73e8bb

File tree

3 files changed

+5
-7
lines changed

3 files changed

+5
-7
lines changed

examples/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
</dependency>
5454
<dependency>
5555
<groupId>io.jooby</groupId>
56-
<artifactId>jooby-utow</artifactId>
56+
<artifactId>jooby-netty</artifactId>
5757
<version>${jooby.version}</version>
5858
</dependency>
5959
<dependency>

examples/src/main/java/examples/HelloApp.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,8 @@ public class HelloApp extends Jooby {
2222

2323
setRouterOptions(new RouterOptions().setIgnoreCase(false).setIgnoreTrailingSlash(true));
2424

25-
after((ctx, result, failure) -> {
26-
throw new RuntimeException("after");
27-
});
28-
2925
get("/", ctx -> {
30-
throw new IllegalArgumentException("handler");
26+
return "Hello World";
3127
});
3228

3329
get("/foo/bar", ctx -> {

modules/jooby-netty/src/main/java/io/jooby/internal/netty/NettyContext.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,9 @@ public NettyContext(ChannelHandlerContext ctx, HttpRequest req, Router router, S
224224

225225
@Nonnull @Override public String getRemoteAddress() {
226226
InetSocketAddress remoteAddress = (InetSocketAddress) ctx.channel().remoteAddress();
227-
return remoteAddress.getAddress().getHostAddress();
227+
String hostAddress = remoteAddress.getAddress().getHostAddress();
228+
int i = hostAddress.lastIndexOf('%');
229+
return i > 0 ? hostAddress.substring(0, i) : hostAddress;
228230
}
229231

230232
@Nonnull @Override public String getProtocol() {

0 commit comments

Comments
 (0)