File tree Expand file tree Collapse file tree
src/main/java/org/example Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1010import java .util .Map ;
1111
1212public 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 ();
You can’t perform that action at this time.
0 commit comments