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

Basic questions #4

Open
beyonlo opened this issue May 14, 2022 · 2 comments
Open

Basic questions #4

beyonlo opened this issue May 14, 2022 · 2 comments

Comments

@beyonlo
Copy link

beyonlo commented May 14, 2022

Hello @marcidy

Well, first congratulations for the great project. I'm starting to use it and I liked so much.

1. How is possible to add Content-Type on the header? Actually all Content-Type response is text/html I would like to add the correct Content-Type to each static file type.
Actually I'm doing this routes on file web.py:

routes = {
    b'/': route('/www/page.htm'),
    b'/static/jquery.js': route('/www/jquery-3.5.1.min.js'),
    b'/static/img1.jpg': route('/www/image1.jpg'),
    b'/static/img2.jpg': route('/www/image2.jpg'),
    b'/static/bootstrap.css': route('/www/bootstrap.min.css'),
    b'/static/favicon.ico': route('/www/favicon.ico')
        }

That routes works fine, but if I reach address http://192.168.43.143/static/img1.jpg will not show the image, just the binary data, because Content-Type is text/html

2. Just a simple bugfix in the doc: In the https://github.com/marcidy/micropython-uasyncio-webexample#phone-home say: "change phone_home in ws.py" but the function name is call_home instead phone_home.

3. My goal is to have just one static page, like as the example page.htm, and to do everything in just one page, using JavaScript + HTML, and communicate with the ESP32-S3 running MicroPython, just using WebSocket, to send and receive data. Well, the question is: do you think that is a good idea to put all interface in just one page? I mean, will be a large page, because I will to do many tabs, many configurations fields, and will have a tab just for monitoring data from sensors, where will receive data from MicroPython when a event happen there, and of course, without request, just waiting a event on WebSocket that will run as a persistent connection. That is what I really want, I would like just to know if that is a really a good idea.

4. Actually I tested your WebSocket example on Firefox, Chromium, Chrome and Opera, and works very well in everyone. My fear is if I develop a complete application web using WebSocket and in the future (in new versions of browsers) my WebSocket application stop to work. Is there that possibility?

5. I would like so much that in the future is possible to use the WebSocket over SSL, like as this feature request #2. So, for now, I will to do everything using your project, without SSL, and when uasyncio start to support SSL (as you commented in #2), I think that you will need do do just few changes in this project to support SSL on WebSocket. Is that correct, or will be need big changes in this project to support that?

Thank you in advance!

@marcidy
Copy link
Owner

marcidy commented May 17, 2022

i would be OK with opening each of those as separate issues in the future, so i can address them independently. No need to do anything, just a note for the future, it's generally easier to handle small issues than large ones that have unrelated parts.

  1. if you look at send_file, you could add a function called send_image which includes the headers.
    I'm hesitant to attempt to make an all-encompassing http[s] server, because not everyone needs every permutation, and there ends up being way more code than what people need. In my opinion, people need to understand how to write their own webserver so they can modify it how they wish.
    Generally everything is a file, so maybe "route" should accept kwargs for additional headers.
    I will think about this, but to quickly have a solution for your project, i suggest modifying 'routes' to accept some parameter which can then switch between a send_file and send_image. I admit this approach will get annoying very quickly as options grow, but at the moment i have time to answer questions but not address a better solution.

  2. thanks, a PR is always acceptable ;)

  3. I think that's a great idea. The more you can do client side, the less effort is required on the device. I do something similar, and it keeps growing as i need more and more access to things, but the point of the page is for diagnostics, so i dont care. Websockets are minimal as opposed to http, so it's better to use this as much as possible for passing relatively small amounts of data imo. tbf these units are powerful enough to handle more, but it's better to conserve resources when you can.

  4. Great. Websockets are a standard handled by IETF: https://www.rfc-editor.org/rfc/rfc6455.html This implementation is not yet 100% compliant but it's "compliant enough". Generally these standards do not break things backwards if they can help it. However, browsers do change, and what they allow gets more and more strict over time. I cannot make any promises, it's on you as the developer to keep track of evolving standards and practices and stay current. generally you should find information sources which track this and pay attention to them.

  5. i haven't had significant time to spend on it, but i have made some progress. The main problem is that the fast/simple stuff is nearly useless, and the useful stuff is complex and takes time to work through, document, and find any issues. i dont have a time frame for this at the moment. At some point it may come up for me as paid work, which will change it's priority.

@beyonlo
Copy link
Author

beyonlo commented May 19, 2022

@marcidy Thank you very much for the all clarification, I appreciate so much!

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