Compare commits

...

2 Commits

Author SHA1 Message Date
Nick Chambers ddab72b438 Add non-volatile inspect definition 2024-04-18 10:26:28 -05:00
Nick Chambers 6a77faa6cf Add rough route implementation 2024-04-18 10:25:57 -05:00
2 changed files with 54 additions and 0 deletions

View File

@ -0,0 +1,5 @@
package com.spookyinternet.cobweb;
public interface HttpInspectFunction {
void process(HttpRequest req);
}

View 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));
}
}
}