webui
webui copied to clipboard
File_Handler Firefox versus Brave
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.
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?
firefox dev tools:
brave dev tools:
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.
Make sure to add Content-Type: application/json in the header response.
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?
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.
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
}
Buffer shows good, when I add that *length line, on the console it shows invalid http request, unable to load resource.
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.
Try char* body = webui_malloc(512 + logo_png_len); // HTTP Header + PNG Data
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?
Okay, I will try to reproduce the issue.
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?