Skip to content
This repository was archived by the owner on Mar 3, 2026. It is now read-only.

Commit fc6a01f

Browse files
committed
req.rawPath fix jooby-project#555
1 parent 42948ac commit fc6a01f

File tree

9 files changed

+81
-2
lines changed

9 files changed

+81
-2
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package org.jooby.issues;
2+
3+
import org.jooby.assets.AssetsBase;
4+
import org.junit.Test;
5+
6+
public class Issue555 extends AssetsBase {
7+
8+
{
9+
get("/555/raw/**", req -> req.rawPath());
10+
get("/555/path/**", req -> req.path());
11+
}
12+
13+
@Test
14+
public void rawPath() throws Exception {
15+
request()
16+
.get("/555/raw/x%252Fy%252Fz")
17+
.expect("/555/raw/x%252Fy%252Fz");
18+
19+
request()
20+
.get("/555/path/x%252Fy%252Fz")
21+
.expect("/555/path/x/y/z");
22+
}
23+
24+
}

jooby-netty/src/main/java/org/jooby/internal/netty/NettyRequest.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,13 @@ public String method() {
121121
return req.method().name();
122122
}
123123

124+
@Override
125+
public String rawPath() {
126+
String uri = req.uri();
127+
int at = uri.indexOf('?');
128+
return at > 0 ? uri.substring(0, at) : uri;
129+
}
130+
124131
@Override
125132
public String path() {
126133
return path;

jooby-servlet/src/main/java/org/jooby/servlet/ServletServletRequest.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,11 @@ public String path() {
9292
return path;
9393
}
9494

95+
@Override
96+
public String rawPath() {
97+
return req.getRequestURI();
98+
}
99+
95100
@Override
96101
public List<String> paramNames() {
97102
return toList(req.getParameterNames());

jooby-undertow/src/main/java/org/jooby/internal/undertow/UndertowRequest.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,11 @@ public String path() {
9797
return path;
9898
}
9999

100+
@Override
101+
public String rawPath() {
102+
return exchange.getRequestURI();
103+
}
104+
100105
@Override
101106
public List<String> paramNames() {
102107
ImmutableList.Builder<String> builder = ImmutableList.<String> builder();

jooby/src/main/java/org/jooby/Request.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,11 @@ public String path() {
126126
return req.path();
127127
}
128128

129+
@Override
130+
public String rawPath() {
131+
return req.rawPath();
132+
}
133+
129134
@Override
130135
public Optional<String> queryString() {
131136
return req.queryString();
@@ -484,6 +489,13 @@ default String path() {
484489
return path(false);
485490
}
486491

492+
/**
493+
* Raw path, like {@link #path()} but without decoding.
494+
*
495+
* @return Raw path, like {@link #path()} but without decoding.
496+
*/
497+
String rawPath();
498+
487499
/**
488500
* The query string, without the leading <code>?</code>.
489501
*

jooby/src/main/java/org/jooby/internal/RequestImpl.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,10 @@ public Route route() {
338338
return route;
339339
}
340340

341+
public String rawPath() {
342+
return req.rawPath();
343+
}
344+
341345
@Override
342346
public String hostname() {
343347
return req.header("host").map(host -> host.split(":")[0]).orElse(ip());

jooby/src/main/java/org/jooby/spi/NativeRequest.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ public interface NativeRequest {
4242
String method();
4343

4444
/**
45-
* @return The part of this request's URL from the protocol
46-
* name up to the query string in the first line of the HTTP request
45+
* @return The part of this request's URL from the protocol name up to the query string in the
46+
* first line of the HTTP request.
4747
*/
4848
String path();
4949

@@ -161,4 +161,9 @@ default void push(final String method, final String path, final Map<String, Obje
161161
throws Exception {
162162
upgrade(NativePushPromise.class).push(method, path, headers);
163163
}
164+
165+
/**
166+
* @return Request path without decoding.
167+
*/
168+
String rawPath();
164169
}

jooby/src/test/java/org/jooby/RequestForwardingTest.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,18 @@ public void path() throws Exception {
6363
});
6464
}
6565

66+
@Test
67+
public void rawPath() throws Exception {
68+
new MockUnit(Request.class)
69+
.expect(unit -> {
70+
Request req = unit.get(Request.class);
71+
expect(req.rawPath()).andReturn("/path");
72+
})
73+
.run(unit -> {
74+
assertEquals("/path", new Request.Forwarding(unit.get(Request.class)).rawPath());
75+
});
76+
}
77+
6678
@Test
6779
public void port() throws Exception {
6880
new MockUnit(Request.class)

jooby/src/test/java/org/jooby/RequestTest.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@ public MediaType type() {
2828
throw new UnsupportedOperationException();
2929
}
3030

31+
@Override
32+
public String rawPath() {
33+
throw new UnsupportedOperationException();
34+
}
35+
3136
@Override
3237
public Optional<String> queryString() {
3338
throw new UnsupportedOperationException();

0 commit comments

Comments
 (0)