parent
4d52590964
commit
74fb2645fd
|
@ -17,7 +17,6 @@
|
||||||
package org.springframework.web.server.support;
|
package org.springframework.web.server.support;
|
||||||
|
|
||||||
import org.springframework.lang.Nullable;
|
import org.springframework.lang.Nullable;
|
||||||
import org.springframework.web.server.ServerWebExchange;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Lookup path information of an incoming HTTP request.
|
* Lookup path information of an incoming HTTP request.
|
||||||
|
@ -32,30 +31,23 @@ public final class LookupPath {
|
||||||
|
|
||||||
private final String path;
|
private final String path;
|
||||||
|
|
||||||
private final int fileExtensionIndex;
|
private final int fileExtStartIndex;
|
||||||
|
|
||||||
private final int pathParametersIndex;
|
private final int fileExtEndIndex;
|
||||||
|
|
||||||
public LookupPath(String path, int fileExtensionIndex, int pathParametersIndex) {
|
public LookupPath(String path, int fileExtStartIndex, int fileExtEndIndex) {
|
||||||
this.path = path;
|
this.path = path;
|
||||||
this.fileExtensionIndex = fileExtensionIndex;
|
this.fileExtStartIndex = fileExtStartIndex;
|
||||||
this.pathParametersIndex = pathParametersIndex;
|
this.fileExtEndIndex = fileExtEndIndex;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getPath() {
|
public String getPath() {
|
||||||
if (this.pathParametersIndex != -1) {
|
|
||||||
// TODO: variant without the path parameter information?
|
|
||||||
//return this.path.substring(0, this.pathParametersIndex);
|
|
||||||
return this.path;
|
return this.path;
|
||||||
}
|
|
||||||
else {
|
|
||||||
return this.path;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getPathWithoutExtension() {
|
public String getPathWithoutExtension() {
|
||||||
if (this.fileExtensionIndex != -1) {
|
if (this.fileExtStartIndex != -1) {
|
||||||
return this.path.substring(0, this.fileExtensionIndex);
|
return this.path.substring(0, this.fileExtStartIndex);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return this.path;
|
return this.path;
|
||||||
|
@ -64,21 +56,15 @@ public final class LookupPath {
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public String getFileExtension() {
|
public String getFileExtension() {
|
||||||
if (this.fileExtensionIndex == -1) {
|
if (this.fileExtStartIndex == -1) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
else if (this.pathParametersIndex == -1) {
|
else if (this.fileExtEndIndex == -1) {
|
||||||
return this.path.substring(this.fileExtensionIndex);
|
return this.path.substring(this.fileExtStartIndex);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return this.path.substring(this.fileExtensionIndex, this.pathParametersIndex);
|
return this.path.substring(this.fileExtStartIndex, this.fileExtEndIndex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
|
||||||
public String getPathParameters() {
|
|
||||||
return this.pathParametersIndex == -1 ?
|
|
||||||
null : this.path.substring(this.pathParametersIndex + 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -46,11 +46,10 @@ public class LookupPathTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void parsePathWithParams() {
|
public void parsePathWithParams() {
|
||||||
LookupPath path = create("/test/foo.txt;foo=bar?framework=spring");
|
LookupPath path = create("/test;spring=framework/foo.txt;foo=bar?framework=spring");
|
||||||
assertEquals("/test/foo.txt;foo=bar", path.getPath());
|
assertEquals("/test;spring=framework/foo.txt;foo=bar", path.getPath());
|
||||||
assertEquals("/test/foo", path.getPathWithoutExtension());
|
assertEquals("/test;spring=framework/foo", path.getPathWithoutExtension());
|
||||||
assertEquals(".txt", path.getFileExtension());
|
assertEquals(".txt", path.getFileExtension());
|
||||||
assertEquals("foo=bar", path.getPathParameters());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private LookupPath create(String path) {
|
private LookupPath create(String path) {
|
||||||
|
|
Loading…
Reference in New Issue