Browse Source

make cars dynamic to load 1 to 6 cars (#114)

For lazy people like me for not having to change the page by hand every
time.
+ adding 2 more cars.
Gregor Hartmann 6 years ago
parent
commit
5cf303de79
4 changed files with 52 additions and 0 deletions
  1. BIN
      http/cars-bugatti.jpg
  2. BIN
      http/cars-mercedes.jpg
  3. 51 0
      http/cars.lua
  4. 1 0
      http/index.html

BIN
http/cars-bugatti.jpg


BIN
http/cars-mercedes.jpg


+ 51 - 0
http/cars.lua

@@ -0,0 +1,51 @@
+return function (connection, req, args)
+   
+   local function showCars(nr)
+      if not nr then return end
+      connection:send([===[<figure><img src="cars-ferrari.jpg" /><figcaption>Ferrari</figcaption></figure>]===])
+      if nr == "1" then return end
+      connection:send([===[<figure><img src="cars-lambo.jpg" /><figcaption>Lamborghini</figcaption></figure>]===])
+      if nr == "2" then return end
+      connection:send([===[<figure><img src="cars-mas.jpg" /><figcaption>Maserati</figcaption></figure>]===])
+      if nr == "3" then return end
+      connection:send([===[<figure><img src="cars-porsche.jpg" /><figcaption>Porsche</figcaption></figure>]===])
+      if nr == "4" then return end
+      connection:send([===[<figure><img src="cars-bugatti.jpg" /><figcaption>Bugatti</figcaption></figure>]===])
+      if nr == "5" then return end
+      connection:send([===[<figure><img src="cars-mercedes.jpg" /><figcaption>Mercedes</figcaption></figure>]===])
+   end
+
+
+   dofile("httpserver-header.lc")(connection, 200, 'html')
+   connection:send([===[
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
+<html lang="en">
+   <head>
+      <meta http-equiv="content-type" content="text/html; charset=utf-8">
+      <title>Nice cars</title>
+   </head>
+   <body>
+      <h1>Nice cars!</h1>
+      <p>
+         This page loads "large" images of fancy cars. It is meant to serve as a stress test for nodemcu-httpserver.<br>
+         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>
+         Whoever manages to modify nodemcu-httpserver to load all four images without crashing wins a prize!
+      </p>
+      <p>
+         choose: <a href="?n=1">show one car</a>
+         <a href="?n=2">show two cars</a>
+         <a href="?n=3">show three cars</a>
+         <a href="?n=4">show four cars</a>
+         <a href="?n=5">show five cars</a>
+         <a href="?n=6">show six cars</a>
+      </p>
+   ]===])
+
+     showCars(args.n)
+   
+   connection:send([===[
+   </body>
+</html>
+   ]===])
+end
+

+ 1 - 0
http/index.html

@@ -22,6 +22,7 @@
       <li><a href="index.html">Index</a>: This page (static)</li>
       <li><a href="hello_world.txt">A text file</a>: Simple text, to verify MIME type is ok. (static)</li>
       <li><a href="cars.html">Nice cars</a>: Stress test, loads several "large" images. Makes the chip panic and restart :( (static)</li>
+      <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>
       <li><a href="counter.html">Count Requests</a>: Stress test, loads the same page over and over, counting every load. (static)</li>
       <li><a href="zipped.html">Zipped</a>: File is actually saved as zipped.html.gz. A compressed file! (static but gzipped)</li>
       <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>