Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/platform/android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ android {
applicationId 'net.sourceforge.smallbasic'
minSdkVersion 19
targetSdkVersion 34
versionCode 60
versionCode 61
versionName '12.27'
resourceConfigurations += ['en']
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1095,7 +1095,8 @@ protected Response getFile(String remoteHost, String path, boolean asset) throws
String name = "webui/" + path;
long length = getFileLength(name);
log("Opened " + name + " " + length + " bytes");
result = new Response(getAssets().open(name), length);
String contentType = path.endsWith("js") ? "text/javascript" : "text/html";
result = new Response(getAssets().open(name), length, contentType);
if ("index.html".equals(path) && isHostNotPermitted(remoteHost)) {
requestHostPermission(remoteHost);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public abstract class WebServer {
private static final int SC_NOT_AUTHORISED = 401;
private static final int SC_NOT_FOUND = 404;
private static final ExecutorService THREAD_POOL = Executors.newCachedThreadPool();
private static final String TEXT_HTML = "text/html";

public WebServer() {
super();
Expand Down Expand Up @@ -641,24 +642,35 @@ public class Response {
private final InputStream inputStream;
private final long length;
private final int errorCode;
private final String contentType;

public Response(InputStream inputStream, long length, String contentType) {
this.inputStream = inputStream;
this.length = length;
this.errorCode = SC_OKAY;
this.contentType = contentType;
}

public Response(InputStream inputStream, long length) {
this.inputStream = inputStream;
this.length = length;
this.errorCode = SC_OKAY;
this.contentType = TEXT_HTML;
}

public Response(byte[] bytes) {
this.inputStream = new ByteArrayInputStream(bytes);
this.length = bytes.length;
this.errorCode = SC_OKAY;
this.contentType = TEXT_HTML;
}

public Response(int errorCode) throws IOException {
byte[] bytes = ("Error: " + errorCode).getBytes(UTF_8);
this.inputStream = new ByteArrayInputStream(bytes);
this.length = bytes.length;
this.errorCode = errorCode;
this.contentType = TEXT_HTML;
}

/**
Expand All @@ -670,7 +682,7 @@ void send(Socket socket, String cookie) throws IOException {
BufferedOutputStream out = new BufferedOutputStream(socket.getOutputStream());
String code = errorCode == SC_OKAY ? SC_OKAY + " OK" : String.valueOf(errorCode);
out.write(("HTTP/1.0 " + code + "\r\n").getBytes(UTF_8));
out.write("Content-type: text/html\r\n".getBytes(UTF_8));
out.write(("Content-type: " + contentType + "\r\n").getBytes(UTF_8));
out.write(contentLength.getBytes(UTF_8));
if (cookie != null) {
out.write(("Set-Cookie: " + TOKEN + "=" + cookie + "\r\n").getBytes(UTF_8));
Expand Down
2 changes: 1 addition & 1 deletion src/platform/android/webui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
},
"scripts": {
"start": "vite --host",
"build": "GENERATE_SOURCEMAP=false vite build && rm ../app/src/main/assets/webui/static/js/main.* && cp -R build/* ../app/src/main/assets/webui/",
"build": "GENERATE_SOURCEMAP=false vite build && rm -rf ../app/src/main/assets/webui/* && cp -R dist/* ../app/src/main/assets/webui/",
"update": "npm update && ncu -u && npm install && npm audit fix"
},
"eslintConfig": {
Expand Down