webui icon indicating copy to clipboard operation
webui copied to clipboard

File_Handler Firefox versus Brave

Open wwderw opened this issue 1 year ago • 4 comments

I was experiment with setting up phaser using this library, but I noticed while everything worked using Firefox, when I tried to run it via the Brave browser, it acted like my file handler wasn't working. It said it wasn't loading the assets that worked under Firefox. I made no changes to the code (I'm using Zig, but not the bindings, I'm using the library directly with Zig). Using the latest daily build compiled using zig's musl.

I don't know if it's the interaction of the library with the Brave browser or if there is something that I may have to do differently.

Most of the time, I use Firefox, so I don't know if this has been an issue before with Brave or if it just has cropped up.

wwderw avatar Oct 11 '24 19:10 wwderw

webui does not do anything different based on browser, so this maybe a web browser issue.

can you share a screenshot of DevTools console F12?

AlbertShown avatar Oct 11 '24 19:10 AlbertShown

firefox dev tools:

firefox

brave dev tools:

brave

wwderw avatar Oct 11 '24 20:10 wwderw

I guess your file handler send an empty MIME type, Firefox is a nice guy, so he accepts it... while Brave is a brave guy, he wants the correct MIME type.

AlbertShown avatar Oct 11 '24 21:10 AlbertShown

Make sure to add Content-Type: application/json in the header response.

AlbertShown avatar Oct 11 '24 21:10 AlbertShown

    char* body = webui_malloc(logo_png_len);
    sprintf(body, "HTTP/1.1 200 OK\nContent-Type: image/png\nContent-Length: %d\n%s", logo_png_len,logo_png);
    printf(body);
    return body;

I have the above setup for just the logo png. Just testing things. I don't get any error in the console, but the results for printf are:

HTTP/1.1 200 OK Content-Type: image/png Content-Length: 10037 �PNG

So it isn't pulling everything in there. I have tried it as a char array and as a str literal and it doesn't seem to want to pull everything in. I'm sure it's something that I'm doing, but since I'm not getting any debug info from the console, I don't know where to go. Am I totally off?

wwderw avatar Nov 05 '24 02:11 wwderw

void print_buffer_hex(const unsigned char *buffer, size_t length) {
    for (size_t i = 0; i < length; i++) {
        printf("%02X ", buffer[i]);
        if ((i + 1) % 16 == 0) {
            printf("\n");
        }
    }
    printf("\n");
}
char* body = webui_malloc(logo_png_len);
sprintf(body, "HTTP/1.1 200 OK\nContent-Type: image/png\nContent-Length: %d\n%s", logo_png_len,logo_png);
print_buffer_hex(logo_png, logo_png_len);
return body;

Try this to make sure your logo buffer has the full data.

AlbertShown avatar Nov 05 '24 13:11 AlbertShown

I just double check, and I guess I know the issue. If you did not tell webui the len of your response, then webui will stop at the first 00 byte.

You need to do it like this:

const void* my_handler_test(const char* path, int* length) {

    char* body = webui_malloc(logo_png_len);
    sprintf(body, "HTTP/1.1 200 OK\nContent-Type: image/png\nContent-Length: %d\n%s", logo_png_len,logo_png);
    printf(body);

    *length = logo_png_len; // Tell webui our response len

    return body; // Give back webui the reponse pointer
}

AlbertShown avatar Nov 05 '24 14:11 AlbertShown

Buffer shows good, when I add that *length line, on the console it shows invalid http request, unable to load resource.

wwderw avatar Nov 05 '24 14:11 wwderw

char* body = webui_malloc(logo_png_len);

I guess here you allocated memory space for logo_png_len, but then you added the HTTP header + logo_png_len.

AlbertShown avatar Nov 05 '24 14:11 AlbertShown

Try char* body = webui_malloc(512 + logo_png_len); // HTTP Header + PNG Data

AlbertShown avatar Nov 05 '24 14:11 AlbertShown

I originally had it larger there, but it still didn't yield anything, so I had taken it off to what you see now.

No change.

Is it it because I'm trying to embed the files using either char array, str literal and or base64 that it can't handle it?

wwderw avatar Nov 05 '24 16:11 wwderw

Okay, I will try to reproduce the issue.

AlbertShown avatar Nov 05 '24 16:11 AlbertShown

Interesting, so I had tried with the latest nim bindings and the 2.5 version didn't work, however the 2.4.2 version did. I used staticRead("path/to/asset") and I was able to get it to work with nothing but returning the variable of the staticRead without setting anything else.

Now the 2.4.2 version of just the pure C did not work with any of the aforementioned ways of embedding that I have tried. Some of it could be the methods of how I was trying to embed the assets since Nim has it built in. The thing that has me going is that it didn't work with the 2.5 version with Nim, but it did with the 2.4.2 version, so I wonder if something went on with the library as well.

But I just know enough to case damage, so I can't swear to any of this.

Where you able to find out anything?

wwderw avatar Nov 09 '24 06:11 wwderw