@Override
public NanoHTTPD.Response serveFile(String uri, Map<String, String> headers, NanoHTTPD.IHTTPSession session, File file, String mimeType) {
String response;
try {
final String contentLength = headers.get("content-length");
if (contentLength == null || contentLength.isEmpty()) {
throw new IllegalStateException("Missing Content-Length header");
}
String code = read(session.getInputStream(), Integer.parseInt(contentLength));
if (code.isEmpty()) {
throw new IllegalArgumentException("Empty code?!");
}
final GrooidShell.EvalResult evaluate = mShell.evaluateOnMainThread(code);
response = evaluate.result != null ? evaluate.result.toString() : "";
} catch (Throwable e) {
response = String.format("%s\n%s", e.getMessage(), LogCatProvider.getStackTrace(e));
}
return new OKResponse(HttpTools.MimeType.APP_OCTET, new ByteArrayInputStream(response.getBytes()));
}