com.litongjava.tio.boot.http.handler.common.WebjarHandler Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of tio-boot Show documentation
Show all versions of tio-boot Show documentation
Java High Performance Web Development Framework
package com.litongjava.tio.boot.http.handler.common;
import java.net.URL;
import com.litongjava.tio.boot.http.TioRequestContext;
import com.litongjava.tio.http.common.HttpRequest;
import com.litongjava.tio.http.common.HttpResponse;
import com.litongjava.tio.http.server.util.Resps;
import com.litongjava.tio.utils.hutool.FileUtil;
import com.litongjava.tio.utils.hutool.ResourceUtil;
public class WebjarHandler {
public HttpResponse index(HttpRequest request) {
HttpResponse response = TioRequestContext.getResponse();
String uri = request.getRequestURI();
String path = "META-INF/resources" + uri;
URL resource = ResourceUtil.getResource(path);
if (resource != null) {
byte[] bytes = FileUtil.readUrlAsBytes(resource);
String extName = FileUtil.extName(uri);
return Resps.bytes(response, bytes, extName);
} else {
response.setStatus(404);
return response;
}
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy