diff options
author | RĂ©mi Verschelde <rverschelde@gmail.com> | 2020-01-14 18:38:16 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-01-14 18:38:16 +0100 |
commit | 16860e90f1e19b2bd1059e0c7032e9ab3c25e319 (patch) | |
tree | 6f9cf7ab3457ab5958da9866d65bbb53016f16ab /platform | |
parent | a5083ef55960d1295a5265e1816665f40838633b (diff) | |
parent | 14a58560e185823af6a9a99700907b4de7b5fba8 (diff) |
Merge pull request #35124 from Faless/js/http_server_fix
Properly close files served by debug HTTP server.
Diffstat (limited to 'platform')
-rw-r--r-- | platform/javascript/export/export.cpp | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/platform/javascript/export/export.cpp b/platform/javascript/export/export.cpp index 93c83f4ff4..9b93d4f140 100644 --- a/platform/javascript/export/export.cpp +++ b/platform/javascript/export/export.cpp @@ -87,16 +87,22 @@ public: String filepath = EditorSettings::get_singleton()->get_cache_dir().plus_file("tmp_js_export"); String basereq = "/tmp_js_export"; + String ctype = ""; if (req[1] == basereq + ".html") { filepath += ".html"; + ctype = "text/html"; } else if (req[1] == basereq + ".js") { filepath += ".js"; + ctype = "application/javascript"; } else if (req[1] == basereq + ".pck") { filepath += ".pck"; + ctype = "application/octet-stream"; } else if (req[1] == basereq + ".png") { filepath += ".png"; + ctype = "image/png"; } else if (req[1] == basereq + ".wasm") { filepath += ".wasm"; + ctype = "application/wasm"; } else { String s = "HTTP/1.1 404 Not Found\r\n"; s += "Connection: Close\r\n"; @@ -109,10 +115,14 @@ public: ERR_FAIL_COND(!f); String s = "HTTP/1.1 200 OK\r\n"; s += "Connection: Close\r\n"; + s += "Content-Type: " + ctype + "\r\n"; s += "\r\n"; CharString cs = s.utf8(); Error err = connection->put_data((const uint8_t *)cs.get_data(), cs.size() - 1); - ERR_FAIL_COND(err != OK); + if (err != OK) { + memdelete(f); + ERR_FAIL(); + } while (true) { uint8_t bytes[4096]; @@ -121,8 +131,12 @@ public: break; } err = connection->put_data(bytes, read); - ERR_FAIL_COND(err != OK); + if (err != OK) { + memdelete(f); + ERR_FAIL(); + } } + memdelete(f); } void poll() { |