Skip to content

Commit 0a53b7f

Browse files
committed
vad problem med github
1 parent 515bc8c commit 0a53b7f

1 file changed

Lines changed: 15 additions & 3 deletions

File tree

src/main/java/org/example/StaticFileHandler.java

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,24 @@
1010
import java.util.Map;
1111

1212
public class StaticFileHandler {
13-
private static final String WEB_ROOT = "www";
14-
private final CacheFilter cacheFilter = new CacheFilter();
13+
private static final String DEFAULT_WEB_ROOT = "www";
14+
private final String webRoot;
15+
private final CacheFilter cacheFilter;
16+
17+
// Standardkonstruktor - använder "www"
18+
public StaticFileHandler() {
19+
this(DEFAULT_WEB_ROOT);
20+
}
21+
22+
// Konstruktor som tar en anpassad webRoot-sökväg (för tester)
23+
public StaticFileHandler(String webRoot) {
24+
this.webRoot = webRoot;
25+
this.cacheFilter = new CacheFilter();
26+
}
1527

1628
public void sendGetRequest(OutputStream outputStream, String uri) throws IOException {
1729
byte[] fileBytes = cacheFilter.getOrFetch(uri,
18-
path -> Files.readAllBytes(new File(WEB_ROOT, path).toPath())
30+
path -> Files.readAllBytes(new File(webRoot, path).toPath())
1931
);
2032

2133
HttpResponseBuilder response = new HttpResponseBuilder();

0 commit comments

Comments
 (0)