Compare commits
2 commits
3971b249d9
...
ddab72b438
Author | SHA1 | Date | |
---|---|---|---|
ddab72b438 | |||
6a77faa6cf |
2 changed files with 54 additions and 0 deletions
5
src/com/spookyinternet/cobweb/HttpInspectFunction.java
Normal file
5
src/com/spookyinternet/cobweb/HttpInspectFunction.java
Normal file
|
@ -0,0 +1,5 @@
|
|||
package com.spookyinternet.cobweb;
|
||||
|
||||
public interface HttpInspectFunction {
|
||||
void process(HttpRequest req);
|
||||
}
|
49
src/com/spookyinternet/cobweb/HttpRoute.java
Normal file
49
src/com/spookyinternet/cobweb/HttpRoute.java
Normal file
|
@ -0,0 +1,49 @@
|
|||
package com.spookyinternet.cobweb;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class HttpRoute {
|
||||
private List<String> pieces;
|
||||
|
||||
public HttpRoute(String path, HttpInspectFunction fn) throws Exception {
|
||||
}
|
||||
|
||||
public HttpRoute(String path, HttpRequestFunction fn) throws Exception {
|
||||
this.pieces = new ArrayList<String>();
|
||||
|
||||
if(path.charAt(0) != '/') {
|
||||
throw new Exception("Invalid HTTP route: " + path);
|
||||
}
|
||||
|
||||
int idx = 0;
|
||||
int marker = 0;
|
||||
|
||||
while(idx < path.length()) {
|
||||
char rune = path.charAt(idx);
|
||||
|
||||
if(rune == '/' || rune == '*') {
|
||||
if(idx > marker) {
|
||||
pieces.add(path.substring(marker, idx));
|
||||
}
|
||||
|
||||
pieces.add(String.valueOf(rune));
|
||||
marker = idx + 1;
|
||||
} else if(rune == '{') {
|
||||
if(idx > marker) {
|
||||
pieces.add(path.substring(marker, idx));
|
||||
}
|
||||
|
||||
marker = idx;
|
||||
} else if(rune == '}') {
|
||||
pieces.add(path.substring(marker, idx + 1));
|
||||
marker = idx + 1;
|
||||
}
|
||||
|
||||
idx += 1;
|
||||
}
|
||||
|
||||
if(idx > marker) {
|
||||
pieces.add(path.substring(marker, idx + 1));
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue