T-vK / NodeMCU-Express

HTTP Web Server library for ESP8266 modules that run the NodeMCU firmware. (Acts like express.js from node.js, but with Lua instead of JavaScript.)
MIT License
19 stars 11 forks source link

bug in HttpServerLua #4

Closed Gennaro001 closed 5 years ago

Gennaro001 commented 5 years ago

on line 173 there are this statement: if body and this._headers['Content-Length'] == nil then if i write this 2 line app:use('/index.html') app:use('/style.css') the _headers['Content-Length'] value remain the length of first file it is send with bad content-length value with undefined result i replaced line 173 with: if body then and now work correctly

T-vK commented 5 years ago

Thanks for reporting. I think I fixed the bug now. The problem was that the headers didn't reset after the response was sent. Although your suggested fix would have worked, my original idea was to give the user complete freedom over if he wants to set the Content-Length by himself or not. Besides that, the bug goes beyond just the Content-Length header. For example if you were to set any other response header e.g. Access-Control-Allow-Origin in one route, it would from there on be sent with the response of every route. So the fix I decided to go with was to simply reset the _headers property to the defaultHeaders. I haven't tested the fix because I don't have an ESP8266 on my hands right now.