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

Conversation

ekharkunov
Copy link
Contributor

@ekharkunov ekharkunov commented May 11, 2024

Add 'path' parameter handling for html5 implementation in http.request function.

Fixes #8234

Technical changes

Previously #8234 can appeared because of default value in dmHttpDDF::HttpResponse::mPath. Here is part of generated source file

char DM_ALIGNED(4) dmHttpDDF_HttpResponse_path_DEFAULT_VALUE[] = "\x00";
dmDDF::FieldDescriptor dmHttpDDF_HttpResponse_FIELDS_DESCRIPTOR[] = 
{
    { "status", 1, 5, 2, 0x0, (uint32_t)DDF_OFFSET_OF(dmHttpDDF::HttpResponse, m_Status), 0x0, 0, 0},
    { "headers", 2, 4, 2, 0x0, (uint32_t)DDF_OFFSET_OF(dmHttpDDF::HttpResponse, m_Headers), 0x0, 0, 0},
    { "headers_length", 3, 13, 2, 0x0, (uint32_t)DDF_OFFSET_OF(dmHttpDDF::HttpResponse, m_HeadersLength), 0x0, 0, 0},
    { "response", 4, 4, 2, 0x0, (uint32_t)DDF_OFFSET_OF(dmHttpDDF::HttpResponse, m_Response), 0x0, 0, 0},
    { "response_length", 5, 13, 2, 0x0, (uint32_t)DDF_OFFSET_OF(dmHttpDDF::HttpResponse, m_ResponseLength), 0x0, 0, 0},
    { "path", 6, 9, 2, 0x0, (uint32_t)DDF_OFFSET_OF(dmHttpDDF::HttpResponse, m_Path), dmHttpDDF_HttpResponse_path_DEFAULT_VALUE, 0, 0},
};

As we see default value for m_Path field is empty string. When we try to rename ._httptmp to m_Path we checked only pointer, not content.

I've added handling of path property for html5 implementation because emscripten can work with fopen/fwrite api (it simulates filesystem https://emscripten.org/docs/getting_started/Tutorial.html#using-files. In my example it looks like

	http.request("", "GET", function(self, id, response)
		pprint(id)
		pprint(response)
	end, {}, nil, { path = "/data/test1.bin"})

Result is
Screenshot 2024-05-11 at 12 26 08

Screenshot 2024-05-11 at 12 26 28

⚠️ Pay attention that if path passed like './data/....' it doesn't work as expected. Path should be passed like '/data/....'.

PR checklist

  • Code
    • Add engine and/or editor unit tests.
    • New and changed code follows the overall code style of existing code
    • Add comments where needed
  • Documentation
    • Make sure that API documentation is updated in code comments
    • Make sure that manuals are updated (in github.com/defold/doc)
  • Prepare pull request and affected issue for automatic release notes generator
    • Pull request - Write a message that explains what this pull request does. What was the problem? How was it solved? What are the changes to APIs or the new APIs introduced? This message will be used in the generated release notes. Make sure it is well written and understandable for a user of Defold.
    • Pull request - Write a pull request title that in a sentence summarises what the pull request does. Do not include "Issue-1234 ..." in the title. This text will be used in the generated release notes.
    • Pull request - Link the pull request to the issue(s) it is closing. Use on of the approved closing keywords.
    • Affected issue - Assign the issue to a project. Do not assign the pull request to a project if there is an issue which the pull request closes.
    • Affected issue - Assign the "breaking change" label to the issue if introducing a breaking change.
    • Affected issue - Assign the "skip release notes" is the issue should not be included in the generated release notes.

Example of a well written PR description:

  1. Start with the user facing changes. This will end up in the release notes.
  2. Add one of the GitHub approved closing keywords
  3. Optionally also add the technical changes made. This is information that might help the reviewer. It will not show up in the release notes. Technical changes are identified by a line starting with one of these:
    1. ### Technical changes
    2. Technical changes:
    3. Technical notes:
There was a anomaly in the carbon chroniton propeller, introduced in version 8.10.2. This fix will make sure to reset the phaser collector on application startup.

Fixes #1234

### Technical changes
* Pay special attention to line 23 of phaser_collector.clj as it contains some interesting optimizations
* The propeller code was not taking into account a negative phase.

@ekharkunov ekharkunov requested a review from AGulev May 11, 2024 09:28
@ekharkunov ekharkunov marked this pull request as ready for review May 11, 2024 09:28
@@ -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.

@ekharkunov ekharkunov merged commit aa1b1d1 into dev May 13, 2024
22 checks passed
@ekharkunov ekharkunov deleted the issue-8234-js-http-path branch May 14, 2024 14:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Failed to rename ‘._httptmp’ to ‘’
2 participants