Skip to content

Commit 5cf303d

Browse files
HHHartmannmarcoskirsch
authored andcommitted
make cars dynamic to load 1 to 6 cars (marcoskirsch#114)
For lazy people like me for not having to change the page by hand every time. + adding 2 more cars.
1 parent ab9a5d3 commit 5cf303d

File tree

4 files changed

+52
-0
lines changed

4 files changed

+52
-0
lines changed

http/cars-bugatti.jpg

12 KB
Loading

http/cars-mercedes.jpg

12 KB
Loading

http/cars.lua

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
return function (connection, req, args)
2+
3+
local function showCars(nr)
4+
if not nr then return end
5+
connection:send([===[<figure><img src="cars-ferrari.jpg" /><figcaption>Ferrari</figcaption></figure>]===])
6+
if nr == "1" then return end
7+
connection:send([===[<figure><img src="cars-lambo.jpg" /><figcaption>Lamborghini</figcaption></figure>]===])
8+
if nr == "2" then return end
9+
connection:send([===[<figure><img src="cars-mas.jpg" /><figcaption>Maserati</figcaption></figure>]===])
10+
if nr == "3" then return end
11+
connection:send([===[<figure><img src="cars-porsche.jpg" /><figcaption>Porsche</figcaption></figure>]===])
12+
if nr == "4" then return end
13+
connection:send([===[<figure><img src="cars-bugatti.jpg" /><figcaption>Bugatti</figcaption></figure>]===])
14+
if nr == "5" then return end
15+
connection:send([===[<figure><img src="cars-mercedes.jpg" /><figcaption>Mercedes</figcaption></figure>]===])
16+
end
17+
18+
19+
dofile("httpserver-header.lc")(connection, 200, 'html')
20+
connection:send([===[
21+
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
22+
<html lang="en">
23+
<head>
24+
<meta http-equiv="content-type" content="text/html; charset=utf-8">
25+
<title>Nice cars</title>
26+
</head>
27+
<body>
28+
<h1>Nice cars!</h1>
29+
<p>
30+
This page loads "large" images of fancy cars. It is meant to serve as a stress test for nodemcu-httpserver.<br>
31+
It works with three embedded images of cars, but the server crashes with four. Select the number of cars you want to see below.<br>
32+
Whoever manages to modify nodemcu-httpserver to load all four images without crashing wins a prize!
33+
</p>
34+
<p>
35+
choose: <a href="?n=1">show one car</a>
36+
<a href="?n=2">show two cars</a>
37+
<a href="?n=3">show three cars</a>
38+
<a href="?n=4">show four cars</a>
39+
<a href="?n=5">show five cars</a>
40+
<a href="?n=6">show six cars</a>
41+
</p>
42+
]===])
43+
44+
showCars(args.n)
45+
46+
connection:send([===[
47+
</body>
48+
</html>
49+
]===])
50+
end
51+

http/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ <h3>Serve me some pages!</h3>
2222
<li><a href="index.html">Index</a>: This page (static)</li>
2323
<li><a href="hello_world.txt">A text file</a>: Simple text, to verify MIME type is ok. (static)</li>
2424
<li><a href="cars.html">Nice cars</a>: Stress test, loads several "large" images. Makes the chip panic and restart :( (static)</li>
25+
<li><a href="cars.lua">Nice cars</a>: Stress test, loads several "large" images. Makes the chip panic and restart :( (dynamic to change number of cars)</li>
2526
<li><a href="counter.html">Count Requests</a>: Stress test, loads the same page over and over, counting every load. (static)</li>
2627
<li><a href="zipped.html">Zipped</a>: File is actually saved as zipped.html.gz. A compressed file! (static but gzipped)</li>
2728
<li><a href="zipped.html.gz">Zipped</a>: Same exact file as served above. Server is smart enough to treat the .gz extension correctly (static but gzipped)</li>

0 commit comments

Comments
 (0)