Skip to content

Instantly share code, notes, and snippets.

@mhansen
Created October 14, 2009 21:01
Show Gist options
  • Save mhansen/210404 to your computer and use it in GitHub Desktop.
Save mhansen/210404 to your computer and use it in GitHub Desktop.
/* Mark Hansen 1082336 */
//uri is in the form /pages/mh168/ or form
public void URI2LocalPath(string uri) {
// convert directory listings to directory/index.html
if (uri.endsWith("/")) uri += "index.html";
//remove first slash so java searches from the local directory, not the root of the filesystem
if (uri.startsWith("/")) uri.replaceFirst("/", "");
}
public void testProcessGETRequest() {
String uri = "/pages/mark/";
String expected = "pages/mark/index.html";
String actual = URI2LocalPath(uri);
assertEquals(expected, actual);
uri = "/";
expected = "index.html";
actual = URI2LocalPath(uri);
assertEquals(expected, actual);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment