Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle 'path' option in http.request for html5 implementation. #8906

Merged
merged 1 commit into from
May 13, 2024
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion engine/gamesys/src/gamesys/scripts/script_http.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ namespace dmGameSystem
* @param [options] [type:table] optional table with request parameters. Supported entries:
*
* - [type:number] `timeout`: timeout in seconds
* - [type:string] `path`: path on disc where to download the file. Only overwrites the path if status is 200. [icon:attention] Not available in HTML5 build
* - [type:string] `path`: path on disc where to download the file. Only overwrites the path if status is 200. [icon:attention] Path should be absolute
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What will happen if IndexedDB isn't supported?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://emscripten.org/docs/api_reference/Filesystem-API.html#memfs
As I understand if no persistent storage is presented - in-memory FS will be used.

* - [type:boolean] `ignore_cache`: don't return cached data if we get a 304. [icon:attention] Not available in HTML5 build
* - [type:boolean] `chunked_transfer`: use chunked transfer encoding for https requests larger than 16kb. Defaults to true. [icon:attention] Not available in HTML5 build
*
Expand Down
8 changes: 8 additions & 0 deletions engine/gamesys/src/gamesys/scripts/script_http_js.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ namespace dmGameSystem
{
dmMessage::URL m_Requester;
void* m_RequestData;
const char* m_Path;
int m_Callback;
};

Expand Down Expand Up @@ -98,6 +99,7 @@ namespace dmGameSystem
resp.m_HeadersLength = headers_length;
resp.m_Response = (uint64_t) response;
resp.m_ResponseLength = response_length;
resp.m_Path = ctx->m_Path;

resp.m_Headers = (uint64_t) malloc(headers_length);
memcpy((void*) resp.m_Headers, headers, headers_length);
Expand Down Expand Up @@ -143,6 +145,7 @@ namespace dmGameSystem
int top = lua_gettop(L);

int callback = 0;
const char* path = 0;
dmMessage::URL sender;
if (dmScript::GetURL(L, &sender)) {
RequestParams request_params;
Expand Down Expand Up @@ -205,6 +208,10 @@ namespace dmGameSystem
{
request_params.m_ReportProgress = lua_toboolean(L, -1);
}
else if (strcmp(attr, "path") == 0)
{
path = luaL_checkstring(L, -1);
}
lua_pop(L, 1);
}
lua_pop(L, 1);
Expand All @@ -214,6 +221,7 @@ namespace dmGameSystem
ctx->m_Callback = callback;
ctx->m_Requester = sender;
ctx->m_RequestData = request_params.m_SendData;
ctx->m_Path = path;

request_params.m_Args = ctx;

Expand Down