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

[bug] setFileHandler() gives invalid http response #69

Open
DevRubicate opened this issue Dec 18, 2024 · 4 comments
Open

[bug] setFileHandler() gives invalid http response #69

DevRubicate opened this issue Dec 18, 2024 · 4 comments

Comments

@DevRubicate
Copy link
Contributor

DevRubicate commented Dec 18, 2024

setFileHandler() appears to serve some sort of invalid http response, making it nonfunctional.

// Show the window
myWindow.show(myHtml); // Or myWindow.show('./myFile.html');

myWindow.setFileHandler((myUrl: URL) => {
  if (myUrl.pathname === '/app.js') return "console.log('hello from client')";
  throw new Error(`Unknown request "${myUrl.pathname}""`)
});

// Wait until all windows get closed
await WebUI.wait();

console.log("Thank you.");

image

I am unfortunately unable to debug why the response is invalid, curl -v was not able to give anything useful.

I am on Windows 11.

@AlbertShown
Copy link
Contributor

To debug this, you have just to use the debug version of webui, this give the full webui logs.
However, I guess webui 2.4 will add HTTP header to the user body response, but webui 2.5 request the user to return the full complete HTTP response (Header + Body).

Try something like:

if (myUrl.pathname === '/app.js') {
  const headers = `HTTP/1.1 200 OK\r\nContent-Type: application/javascript\r\n`;
  const body = "console.log('hello from client');";
  return `${headers}\r\n${body}`;
}

@DevRubicate
Copy link
Contributor Author

Aha! That is a good change, I approve.

However, when I try your example, I get one more byte of output than I am supposed to get. I checked with curl and it the extra byte is 0x00, I assume this is the termination of a C-style string?

image

@AlbertShown
Copy link
Contributor

AlbertShown commented Dec 18, 2024

I don't know if this extra byte is added by Deno wrapper, or by webui core.
Can you try adding HTTP content len and see if it gets fixed?

if (myUrl.pathname === '/app.js') {
  const body = "console.log('hello from client');";
  const headers = `HTTP/1.1 200 OK\r\nContent-Type: application/javascript\r\nContent-Length: ${body.length}\r\n`;
  return `${headers}\r\n${body}`;
}

@DevRubicate
Copy link
Contributor Author

It does fix it, thank you.

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

No branches or pull requests

2 participants