Comments (4)
I looked at this from the MicroPython uasyncio side. Using the tinyweb's examples/hello_world.py example, but with some sleeps shows the behavior @UnexpectedMaker describes, however if you connect manually (e.g. via telnet) you can see that the data is flushed immediately. This is just how browsers work. It seems that you need to get past some minimum number of bytes in the response before the browser will start rendering the page, e.g. this works fine:
@app.route('/')
async def index(request, response):
# Start HTTP response with content-type text/html
await response.start_html()
# Send actual HTML page
await response.send('<html><body><h1>Hello</h1>\n')
await response.send(' ' * 1024) # <-- Make the browser start rendering.
for _ in range(5):
await uasyncio.sleep(5)
await response.send('<h2>hello</h2>\n')
await response.send('</html>\n')
FYI @belyalov , MicroPython is going to release a new version of uasyncio soon. See micropython/micropython#5332
Unfortunately this will break TinyWeb due to some internal dependencies it has on (for example uasyncio.IORead ) For the most part, moving to uasyncio.start_server will solve this.
from tinyweb.
@UnexpectedMaker: @jimmo is right - this is how browser works.
Usually, to force browser to show/process received data immediately either chunks or close connection could be used.
So you can try to switch your handler to be generator (to force tinyweb to use Transfer-Encoding: chunked
), like this:
async def something():
yield '<h2>Credentials saved!</h2><br>You can now close this page...'
yield html.format(self.web_title, st_str)
# ...
test: https://github.com/belyalov/tinyweb/blob/master/test/test_server.py#L283
implementation: https://github.com/belyalov/tinyweb/blob/master/tinyweb/server.py#L327
from tinyweb.
FYI @belyalov , MicroPython is going to release a new version of uasyncio soon. See micropython/micropython#5332
Unfortunately this will break TinyWeb due to some internal dependencies it has on (for example uasyncio.IORead ) For the most part, moving to uasyncio.start_server will solve this.
This is actually great - I'll adapt tinyweb once PR merged.
Thanks
from tinyweb.
Yeah, new asyncio looks promising and much easier for noobs like me to grok!
Thanks for your help on this issue @belyalov and @jimmo - working great now, so closing it!
from tinyweb.
Related Issues (20)
- Connection closed without response on nonexistent paths HOT 18
- Kernel Panic serving anything if local MicroDNSSrv used HOT 8
- No CaptivePortal support? HOT 6
- Still can't get captive portals working :( HOT 2
- Updated tinyweb for new uasyncio? HOT 10
- Task exception wasn't retrieved HOT 1
- Question: tinyweb on esp8266 compared to other frameworks HOT 3
- Disable CodeFactor.io warning HOT 1
- tinyweb.mpy not working HOT 1
- Some functions are not working
- Build flash file for ESP01 1M ? HOT 1
- Regarding blinking LED HOT 1
- websockets HOT 6
- shutdown() tries to access non-existent attribute "cancel" on uasyncio module HOT 2
- `read_headers` should be case-insensitive on keys
- This is NOT an issue - more a request
- tinyweb not working above micropython ESP32 firmware 1.19 HOT 1
- Logger calls exc instead of exception HOT 4
- Create Documentation in Sphinx reStructuredText Format. HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from tinyweb.