set here [file dirname [file join [pwd] [info script]]]
source [file join $here slides.tcl]


set obj [::html_slidemaker::object new]

$obj slide {
<h1 style="text-align: center;   vertical-align: top;">The Httpd Module and Toadhttpd</h1>
<p style="text-align: center;">Sean Woods<br>
<p style="text-align: center;">Test &amp; Evaluation Solutions, LLC<br>
}

$obj slide {
In this presentation we will cover:
} ul {
} li {
Why we need a reference web server
} li {
The Httpd Module in Tcllib
} li {
The Toadhttpd web server project
} /ul {}

$obj slide {
On an interesting note, this presentation is running from an instance of Httpd
<p>
Folks at home can tune into:<p>
<a href="http://www.etoyoc.com/yoda/papers/tcl2018/Httpd_Slides.html">
http://www.etoyoc.com/yoda/papers/tcl2018/Httpd_Slides.html</a>
</p>
and replay this presentation on their own.
} div {
It's actually a cute bit of Javascript I <strike>stole</strike>
picked up from Cyan Ogilvie.
}

$obj slide {
<table>
<tr><td>
<img src=lg-oops.jpg>
</td>
<td>
Error serving <b>/yoda/papers/tcl2018.Httpd_slides.tml</b>:
<p>
The server encountered an internal server error:
<pre>
Must crash here
</pre>
<pre><code>
 while executing
"error "Must Crash here""
    invoked from within
"subst $tmltxt"
    (class "::httpd::content.file" method "content" line 42)
    invoked from within
"my content"
</code></pre>
</td></tr>
</table>
<hr>
<i>This is just joke, go onto the next slide</i>
}

$obj slide {
<img src=haha.jpg>
}

$obj slide {
<h1 style="text-align: center; vertical-align: top;">Why we need a reference web server</h1>
The user interface of choice in this day an age is no longer Tk.
}

$obj slide {
<img src=heretic.gif>
}


$obj slide {
<h1 style="text-align: center; vertical-align: top;">Why we need a reference web server</h1>
The user interface of choice in this day an age is no longer Tk:
} ul {
} li {Tcl needs to explore new ways of generating human machine interfaces.
} li {Newer platforms are stressing browser based interactions.
} li {Especially on mobile platforms.
} /ul {
} div {
<i>But hypnotoad, don't we already have a host of web servers for Tcl already?</i>
}

$obj slide {
<h1 style="text-align: center; vertical-align: top;">Why we need a <b>REFERENCE</b> web server</h1>
<p>
The Tcl community has already developed a number of web servers.
<p>
The problem is: <ul>
} li {
The serious implementations are too massive, complex, and/or needy to be embedded in a desktop application.
} li {
The embeddable implementations are basically toys.
} li {
The implementations which support server side scripting,
each go off an implement server side scripting in a completely different way.
} li {
Testing. Testing. Testing.
} /ul {}

$obj slide {
<h1 style="text-align: center; vertical-align: top;">The Httpd Module</h1>
} ul {
} li {
Started off life as version 4 of Tclhttpd.
} li {
Introduced Coroutines and TclOO to the core of the httpd server
} li {
Added bootstrap and jquery integration
} li {
Added a highly adaptable dispatch engine
} li {
Server was implemented as an OO object
} li {
Could be loaded in a package inside of normal Tcl software
} /ul {
} div {
Ended up being nothing like Tclhttpd.
<img src=bee.gif>
}

$obj slide {
<h1 style="text-align: center; vertical-align: top;">Simple Dustmote Example:</h1>
<pre><code>
package require httpd

::httpd::server create HTTPD port 8015 doc_root ~/htdocs
HTTPD start
</code></pre>
} div {
<i>QED</i>
}

$obj slide {
<svg width="800" height="600" xmlns="http://www.w3.org/2000/svg" xmlns:svg="http://www.w3.org/2000/svg">
 <!-- Created with SVG-edit - http://svg-edit.googlecode.com/ -->
 <g>
  <title>Layer 1</title>
  <polygon id="svg_10" fill="#007fff"/>
  <polygon id="svg_11" fill="#007fff"/>
  <polygon id="svg_12" fill="#007fff"/>
  <line fill="none" stroke="#000000" stroke-width="5" stroke-dasharray="null" stroke-linejoin="null" stroke-linecap="null" x1="288" y1="380" x2="289" y2="380" id="svg_45"/>
  <text stroke="#000000" transform="matrix(4.0764 0 0 4.88423 -752.747 -665.692)" xml:space="preserve" text-anchor="middle" font-family="Fantasy" font-size="24" id="svg_1" y="164.17801" x="244.148285" stroke-linecap="null" stroke-linejoin="null" stroke-dasharray="null" stroke-width="0" fill="#000000">But Wait:</text>
  <text stroke="#000000" transform="matrix(3.60952 0 0 6.2794 -214.877 -1826.59)" xml:space="preserve" text-anchor="middle" font-family="Serif" font-size="24" id="svg_2" y="352.303061" x="153.865145" stroke-linecap="null" stroke-linejoin="null" stroke-dasharray="null" stroke-width="0" fill="#000000">There&#x27;s MORE</text>
 </g>
</svg>
}

$obj slide {
<svg width="800" height="350" xmlns="http://www.w3.org/2000/svg" xmlns:svg="http://www.w3.org/2000/svg">
 <!-- Created with SVG-edit - http://svg-edit.googlecode.com/ -->
 <g>
  <title>Layer 1</title>
  <rect stroke="#000000" id="svg_1" height="236.999992" width="192.000003" y="85" x="56" stroke-width="5" fill="#007fff"/>
  <rect stroke="#000000" id="svg_2" height="243.000004" width="181.999994" y="82.999996" x="380.000006" stroke-width="5" fill="#bfbfbf"/>
  <text stroke="#000000" transform="matrix(1 0 0 1.03636 0 -4.65454)" xml:space="preserve" text-anchor="middle" font-family="serif" font-size="24" id="svg_3" y="121.035088" x="143" stroke-linecap="null" stroke-linejoin="null" stroke-dasharray="null" stroke-width="0" fill="#000000">Server</text>
  <text xml:space="preserve" text-anchor="middle" font-family="serif" font-size="24" id="svg_4" y="113" x="467" stroke-linecap="null" stroke-linejoin="null" stroke-dasharray="null" stroke-width="0" stroke="#000000" fill="#000000">Reply</text>
  <rect stroke="#000000" id="svg_5" height="111" width="266" y="151" x="184" stroke-linecap="null" stroke-linejoin="null" stroke-dasharray="null" stroke-width="5" fill="#00ff7f"/>
  <text xml:space="preserve" text-anchor="middle" font-family="serif" font-size="24" id="svg_6" y="205" x="316" stroke-linecap="null" stroke-linejoin="null" stroke-dasharray="null" stroke="#000000" fill="#00ff7f">Coroutine</text>
 </g>
</svg>
<p>
There are three players: The Server, the Coroutine, and the Reply Object
}

$obj slide {
<h1 style="text-align: center; vertical-align: top;">The players</h1>
<svg width="800" height="350" xmlns="http://www.w3.org/2000/svg" xmlns:svg="http://www.w3.org/2000/svg">
 <!-- Created with SVG-edit - http://svg-edit.googlecode.com/ -->
 <defs>
  <marker refY="50" refX="50" markerHeight="5" markerWidth="5" viewBox="0 0 100 100" se_type="rightarrow" orient="auto" markerUnits="strokeWidth" id="se_marker_end_svg_15">
   <path stroke-width="10" stroke="#000000" fill="#000000" d="m100,50l-100,40l30,-40l-30,-40z"/>
  </marker>
 </defs>
 <g>
  <title>Layer 1</title>
  <rect stroke="#000000" id="svg_1" height="236.999992" width="192.000003" y="49" x="228" stroke-width="5" fill="#007fff"/>
  <text stroke="#000000" transform="matrix(1 0 0 1.03636 0 -4.65454)" xml:space="preserve" text-anchor="middle" font-family="serif" font-size="24" id="svg_3" y="99.807017" x="320" stroke-linecap="null" stroke-linejoin="null" stroke-dasharray="null" stroke-width="0" fill="#000000">Server</text>
  <polygon stroke-width="5" stroke="#000000" points="121.69892883300781,174 89.4307632446289,218.41331481933594 37.21977233886719,201.44894409179688 37.21977233886719,146.55105590820312 89.4307632446289,129.586669921875 121.69892883300781,174 " strokeWidth="5" strokecolor="#000000" fill="#7fff00" edge="54.897885" orient="x" sides="5" shape="regularPoly" id="svg_8" cy="110" cx="42"/>
  <polygon strokeWidth="5" strokecolor="#000000" fill="#007fff" edge="0" orient="x" sides="5" shape="regularPoly" id="svg_10" cy="167" cx="105"/>
  <polygon strokeWidth="5" strokecolor="none" fill="#007fff" edge="0" orient="x" sides="5" shape="regularPoly" id="svg_11" cy="127" cx="92"/>
  <polygon strokeWidth="5" strokecolor="none" fill="#007fff" edge="0" orient="x" sides="5" shape="regularPoly" id="svg_12" cy="127" cx="96"/>
  <text xml:space="preserve" text-anchor="middle" font-family="serif" font-size="24" id="svg_13" y="180" x="73" stroke-linecap="null" stroke-linejoin="null" stroke-dasharray="null" stroke-width="0" stroke="#000000" fill="#000000">Socket</text>
  <text xml:space="preserve" text-anchor="middle" font-family="serif" font-size="24" id="svg_14" y="199" x="319" stroke-linecap="null" stroke-linejoin="null" stroke-dasharray="null" stroke-width="0" stroke="#000000" fill="#000000">method connect</text>
  <line marker-end="url(#se_marker_end_svg_15)" stroke="#000000" id="svg_15" y2="186" x2="209.999997" y1="173" x1="132" stroke-linecap="null" stroke-linejoin="null" stroke-dasharray="null" stroke-width="5" fill="none"/>
 </g>
</svg>
<p>
The process starts when a socket event invokes a call to the server's connect method.
}
$obj slide {
<h1 style="text-align: center; vertical-align: top;">The players</h1>
<svg width="800" height="350" xmlns="http://www.w3.org/2000/svg" xmlns:svg="http://www.w3.org/2000/svg">
 <!-- Created with SVG-edit - http://svg-edit.googlecode.com/ -->
 <defs>
  <marker refY="50" refX="50" markerHeight="5" markerWidth="5" viewBox="0 0 100 100" se_type="rightarrow" orient="auto" markerUnits="strokeWidth" id="se_marker_end_svg_15">
   <path stroke-width="10" stroke="#000000" fill="#000000" d="m100,50l-100,40l30,-40l-30,-40z"/>
  </marker>
 </defs>
 <g>
  <title>Layer 1</title>
  <rect stroke="#000000" id="svg_1" height="236.999992" width="192.000003" y="49" x="228" stroke-width="5" fill="#007fff"/>
  <text stroke="#000000" transform="matrix(1 0 0 1.03636 0 -4.65454)" xml:space="preserve" text-anchor="middle" font-family="serif" font-size="24" id="svg_3" y="99.807017" x="320" stroke-linecap="null" stroke-linejoin="null" stroke-dasharray="null" stroke-width="0" fill="#000000">Server</text>
  <polygon stroke-width="5" stroke="#000000" points="121.69892883300781,174 89.4307632446289,218.41331481933594 37.21977233886719,201.44894409179688 37.21977233886719,146.55105590820312 89.4307632446289,129.586669921875 121.69892883300781,174 " strokeWidth="5" strokecolor="#000000" fill="#7fff00" edge="54.897885" orient="x" sides="5" shape="regularPoly" id="svg_8" cy="110" cx="42"/>
  <polygon strokeWidth="5" strokecolor="#000000" fill="#007fff" edge="0" orient="x" sides="5" shape="regularPoly" id="svg_10" cy="167" cx="105"/>
  <polygon strokeWidth="5" strokecolor="none" fill="#007fff" edge="0" orient="x" sides="5" shape="regularPoly" id="svg_11" cy="127" cx="92"/>
  <polygon strokeWidth="5" strokecolor="none" fill="#007fff" edge="0" orient="x" sides="5" shape="regularPoly" id="svg_12" cy="127" cx="96"/>
  <text xml:space="preserve" text-anchor="middle" font-family="serif" font-size="24" id="svg_13" y="180" x="73" stroke-linecap="null" stroke-linejoin="null" stroke-dasharray="null" stroke-width="0" stroke="#000000" fill="#000000">Socket</text>
  <text xml:space="preserve" text-anchor="middle" font-family="serif" font-size="24" id="svg_14" y="199" x="319" stroke-linecap="null" stroke-linejoin="null" stroke-dasharray="null" stroke-width="0" stroke="#000000" fill="#000000">method connect</text>
  <line marker-end="url(#se_marker_end_svg_15)" stroke="#000000" id="svg_15" y2="186" x2="209.999997" y1="173" x1="132" stroke-linecap="null" stroke-linejoin="null" stroke-dasharray="null" stroke-width="5" fill="none"/>
  <rect id="svg_16" height="250" width="146" y="50" x="463" stroke-linecap="null" stroke-linejoin="null" stroke-dasharray="null" stroke-width="5" stroke="#000000" fill="#ff7f00"/>
  <text stroke-opacity="0" xml:space="preserve" text-anchor="middle" font-family="serif" font-size="24" id="svg_24" y="82" x="533" stroke-linecap="null" stroke-linejoin="null" stroke-dasharray="null" stroke-width="null" stroke="#000000" fill="#000000">Coroutine</text>
 </g>
</svg>
<p>
The connect method creates a coroutine which takes control of the socket, and
uses the private Connect method of the server to bootstrap the rest of the reply
process.
}

$obj slide {
<h1 style="text-align: center; vertical-align: top;">The players</h1>
<svg width="800" height="350" xmlns="http://www.w3.org/2000/svg" xmlns:svg="http://www.w3.org/2000/svg">
 <!-- Created with SVG-edit - http://svg-edit.googlecode.com/ -->
 <defs>
  <marker refY="50" refX="50" markerHeight="5" markerWidth="5" viewBox="0 0 100 100" se_type="rightarrow" orient="auto" markerUnits="strokeWidth" id="se_marker_end_svg_25">
   <path stroke-width="10" stroke="#000000" fill="#000000" d="m100,50l-100,40l30,-40l-30,-40z"/>
  </marker>
 </defs>
 <g>
  <title>Layer 1</title>
  <rect id="svg_16" height="250" width="146" y="47" x="247" stroke-linecap="null" stroke-linejoin="null" stroke-dasharray="null" stroke-width="5" stroke="#000000" fill="#ff7f00"/>
  <text xml:space="preserve" text-anchor="middle" font-family="serif" font-size="24" id="svg_26" y="106" x="88" stroke-linecap="null" stroke-linejoin="null" stroke-dasharray="null" stroke-width="0" stroke="#000000" fill="#000000">Connect</text>
  <rect stroke="#000000" id="svg_1" height="236.999992" width="192.000003" y="28" x="21" stroke-width="5" fill="#007fff"/>
  <line marker-end="url(#se_marker_end_svg_25)" id="svg_25" y2="98" x2="155" y1="98" x1="265" stroke-linecap="null" stroke-linejoin="null" stroke-dasharray="null" stroke-width="5" stroke="#000000" fill="none"/>
  <text stroke="#000000" transform="matrix(1 0 0 1.03636 0 -4.65454)" xml:space="preserve" text-anchor="middle" font-family="serif" font-size="24" id="svg_3" y="64.105261" x="104" stroke-linecap="null" stroke-linejoin="null" stroke-dasharray="null" stroke-width="0" fill="#000000">Server</text>
  <polygon stroke-width="5" stroke="#000000" points="365.69891357421875,152 333.4307861328125,196.41329956054688 281.21978759765625,179.44894409179688 281.21978759765625,124.55105590820312 333.4307861328125,107.586669921875 365.69891357421875,152 " strokeWidth="5" strokecolor="#000000" fill="#7fff00" edge="54.897885" orient="x" sides="5" shape="regularPoly" id="svg_8" cy="110" cx="42"/>
  <polygon strokeWidth="5" strokecolor="#000000" fill="#007fff" edge="0" orient="x" sides="5" shape="regularPoly" id="svg_10" cy="167" cx="105"/>
  <polygon strokeWidth="5" strokecolor="none" fill="#007fff" edge="0" orient="x" sides="5" shape="regularPoly" id="svg_11" cy="127" cx="92"/>
  <polygon strokeWidth="5" strokecolor="none" fill="#007fff" edge="0" orient="x" sides="5" shape="regularPoly" id="svg_12" cy="127" cx="96"/>
  <text xml:space="preserve" text-anchor="middle" font-family="serif" font-size="24" id="svg_13" y="160" x="321" stroke-linecap="null" stroke-linejoin="null" stroke-dasharray="null" stroke-width="0" stroke="#000000" fill="#000000">Socket</text>
  <text stroke-opacity="0" xml:space="preserve" text-anchor="middle" font-family="serif" font-size="24" id="svg_24" y="79" x="317" stroke-linecap="null" stroke-linejoin="null" stroke-dasharray="null" stroke-width="null" stroke="#000000" fill="#000000">Coroutine</text>
  <text id="svg_27" xml:space="preserve" text-anchor="middle" font-family="serif" font-size="24" y="108.75" x="92.5" stroke-linecap="null" stroke-linejoin="null" stroke-dasharray="null" stroke-width="0" stroke="#000000" fill="#000000">Connect</text>
  <text style="cursor: move;" id="svg_28" xml:space="preserve" text-anchor="middle" font-family="serif" font-size="24" y="149.75" x="90.5" stroke-linecap="null" stroke-linejoin="null" stroke-dasharray="null" stroke-width="0" stroke="#000000" fill="#000000">dispatch</text>
 </g>
</svg>
<p>
The coroutine reads the request line and the MIME headers, and passes that
information to the Server's dispatch method
}

$obj slide {
<h1 style="text-align: center; vertical-align: top;">The players</h1>
<svg width="800" height="350" xmlns="http://www.w3.org/2000/svg" xmlns:svg="http://www.w3.org/2000/svg">
 <!-- Created with SVG-edit - http://svg-edit.googlecode.com/ -->
 <defs>
  <marker refY="50" refX="50" markerHeight="5" markerWidth="5" viewBox="0 0 100 100" se_type="rightarrow" orient="auto" markerUnits="strokeWidth" id="se_marker_end_svg_25">
   <path stroke-width="10" stroke="#000000" fill="#000000" d="m100,50l-100,40l30,-40l-30,-40z"/>
  </marker>
  <marker refY="50" refX="50" markerHeight="5" markerWidth="5" viewBox="0 0 100 100" se_type="rightarrow" orient="auto" markerUnits="strokeWidth" id="se_marker_end_svg_32">
   <path stroke-width="10" stroke="#000000" fill="#000000" d="m100,50l-100,40l30,-40l-30,-40z"/>
  </marker>
 </defs>
 <g>
  <title>Layer 1</title>
  <rect id="svg_16" height="250" width="146" y="47" x="247" stroke-linecap="null" stroke-linejoin="null" stroke-dasharray="null" stroke-width="5" stroke="#000000" fill="#ff7f00"/>
  <text xml:space="preserve" text-anchor="middle" font-family="serif" font-size="24" id="svg_26" y="106" x="88" stroke-linecap="null" stroke-linejoin="null" stroke-dasharray="null" stroke-width="0" stroke="#000000" fill="#000000">Connect</text>
  <rect stroke="#000000" id="svg_1" height="236.999992" width="192.000003" y="28" x="21" stroke-width="5" fill="#007fff"/>
  <line marker-end="url(#se_marker_end_svg_25)" id="svg_25" y2="98" x2="155" y1="98" x1="265" stroke-linecap="null" stroke-linejoin="null" stroke-dasharray="null" stroke-width="5" stroke="#000000" fill="none"/>
  <text stroke="#000000" transform="matrix(1 0 0 1.03636 0 -4.65454)" xml:space="preserve" text-anchor="middle" font-family="serif" font-size="24" id="svg_3" y="64.105261" x="104" stroke-linecap="null" stroke-linejoin="null" stroke-dasharray="null" stroke-width="0" fill="#000000">Server</text>
  <polygon stroke-width="5" stroke="#000000" points="365.69891357421875,152 333.4307861328125,196.41329956054688 281.21978759765625,179.44894409179688 281.21978759765625,124.55105590820312 333.4307861328125,107.586669921875 365.69891357421875,152 " strokeWidth="5" strokecolor="#000000" fill="#7fff00" edge="54.897885" orient="x" sides="5" shape="regularPoly" id="svg_8" cy="110" cx="42"/>
  <polygon strokeWidth="5" strokecolor="#000000" fill="#007fff" edge="0" orient="x" sides="5" shape="regularPoly" id="svg_10" cy="167" cx="105"/>
  <polygon strokeWidth="5" strokecolor="none" fill="#007fff" edge="0" orient="x" sides="5" shape="regularPoly" id="svg_11" cy="127" cx="92"/>
  <polygon strokeWidth="5" strokecolor="none" fill="#007fff" edge="0" orient="x" sides="5" shape="regularPoly" id="svg_12" cy="127" cx="96"/>
  <text xml:space="preserve" text-anchor="middle" font-family="serif" font-size="24" id="svg_13" y="160" x="321" stroke-linecap="null" stroke-linejoin="null" stroke-dasharray="null" stroke-width="0" stroke="#000000" fill="#000000">Socket</text>
  <text stroke-opacity="0" xml:space="preserve" text-anchor="middle" font-family="serif" font-size="24" id="svg_24" y="79" x="317" stroke-linecap="null" stroke-linejoin="null" stroke-dasharray="null" stroke-width="null" stroke="#000000" fill="#000000">Coroutine</text>
  <text id="svg_27" xml:space="preserve" text-anchor="middle" font-family="serif" font-size="24" y="108.75" x="92.5" stroke-linecap="null" stroke-linejoin="null" stroke-dasharray="null" stroke-width="0" stroke="#000000" fill="#000000">Connect</text>
  <text style="cursor: move;" id="svg_28" xml:space="preserve" text-anchor="middle" font-family="serif" font-size="24" y="149.75" x="90.5" stroke-linecap="null" stroke-linejoin="null" stroke-dasharray="null" stroke-width="0" stroke="#000000" fill="#000000">dispatch</text>
  <line stroke="#000000" marker-end="url(#se_marker_end_svg_32)" id="svg_32" y2="231" x2="241.999997" y1="230" x1="147" stroke-linecap="null" stroke-linejoin="null" stroke-dasharray="null" stroke-width="5" fill="none"/>
  <ellipse ry="41" rx="60" id="svg_33" cy="239" cx="313" stroke-linecap="null" stroke-linejoin="null" stroke-dasharray="null" stroke-width="5" stroke="#000000" fill="#ffff00"/>
  <text xml:space="preserve" text-anchor="middle" font-family="serif" font-size="24" id="svg_35" y="250" x="317" stroke-linecap="null" stroke-linejoin="null" stroke-dasharray="null" stroke-width="0" stroke="#000000" fill="#000000">Dict</text>
 </g>
</svg>
<p>
The dispatch method returns a dict
}

$obj slide {
<h1 style="text-align: center; vertical-align: top;">The players</h1>
<svg width="800" height="350" xmlns="http://www.w3.org/2000/svg" xmlns:svg="http://www.w3.org/2000/svg">
 <!-- Created with SVG-edit - http://svg-edit.googlecode.com/ -->

 <g>
  <title>Layer 1</title>
  <rect id="svg_16" height="250" width="146" y="47" x="247" stroke-linecap="null" stroke-linejoin="null" stroke-dasharray="null" stroke-width="5" stroke="#000000" fill="#ff7f00"/>
  <text xml:space="preserve" text-anchor="middle" font-family="serif" font-size="24" id="svg_26" y="106" x="88" stroke-linecap="null" stroke-linejoin="null" stroke-dasharray="null" stroke-width="0" stroke="#000000" fill="#000000">Connect</text>
  <rect stroke="#000000" id="svg_1" height="236.999992" width="192.000003" y="28" x="21" stroke-width="5" fill="#007fff"/>
  <text stroke="#000000" transform="matrix(1 0 0 1.03636 0 -4.65454)" xml:space="preserve" text-anchor="middle" font-family="serif" font-size="24" id="svg_3" y="64.105261" x="104" stroke-linecap="null" stroke-linejoin="null" stroke-dasharray="null" stroke-width="0" fill="#000000">Server</text>
  <polygon stroke-width="5" stroke="#000000" points="365.69891357421875,152 333.4307861328125,196.41329956054688 281.21978759765625,179.44894409179688 281.21978759765625,124.55105590820312 333.4307861328125,107.586669921875 365.69891357421875,152 " strokeWidth="5" strokecolor="#000000" fill="#7fff00" edge="54.897885" orient="x" sides="5" shape="regularPoly" id="svg_8" cy="110" cx="42"/>
  <polygon strokeWidth="5" strokecolor="#000000" fill="#007fff" edge="0" orient="x" sides="5" shape="regularPoly" id="svg_10" cy="167" cx="105"/>
  <polygon strokeWidth="5" strokecolor="none" fill="#007fff" edge="0" orient="x" sides="5" shape="regularPoly" id="svg_11" cy="127" cx="92"/>
  <polygon strokeWidth="5" strokecolor="none" fill="#007fff" edge="0" orient="x" sides="5" shape="regularPoly" id="svg_12" cy="127" cx="96"/>
  <text xml:space="preserve" text-anchor="middle" font-family="serif" font-size="24" id="svg_13" y="160" x="321" stroke-linecap="null" stroke-linejoin="null" stroke-dasharray="null" stroke-width="0" stroke="#000000" fill="#000000">Socket</text>
  <text stroke-opacity="0" xml:space="preserve" text-anchor="middle" font-family="serif" font-size="24" id="svg_24" y="79" x="317" stroke-linecap="null" stroke-linejoin="null" stroke-dasharray="null" stroke-width="null" stroke="#000000" fill="#000000">Coroutine</text>
  <ellipse ry="41" rx="60" id="svg_33" cy="239" cx="313" stroke-linecap="null" stroke-linejoin="null" stroke-dasharray="null" stroke-width="5" stroke="#000000" fill="#ffff00"/>
  <text xml:space="preserve" text-anchor="middle" font-family="serif" font-size="24" id="svg_35" y="250" x="317" stroke-linecap="null" stroke-linejoin="null" stroke-dasharray="null" stroke-width="0" stroke="#000000" fill="#000000">Dict</text>
  <rect id="svg_36" height="245" width="205" y="32" x="422" stroke-linecap="null" stroke-linejoin="null" stroke-dasharray="null" stroke-width="5" stroke="#000000" fill="#007fff"/>
  <text xml:space="preserve" text-anchor="middle" font-family="serif" font-size="24" id="svg_37" y="73" x="514" stroke-linecap="null" stroke-linejoin="null" stroke-dasharray="null" stroke-width="0" stroke="#000000" fill="#000000">Reply</text>
 </g>
</svg>
<p>
The coroutine then creates an instance of httpd::reply
}

$obj slide {
<h1 style="text-align: center; vertical-align: top;">The players</h1>
<svg width="800" height="350" xmlns="http://www.w3.org/2000/svg" xmlns:svg="http://www.w3.org/2000/svg">
 <!-- Created with SVG-edit - http://svg-edit.googlecode.com/ -->
 <defs>
  <marker refY="50" refX="50" markerHeight="5" markerWidth="5" viewBox="0 0 100 100" se_type="rightarrow" orient="auto" markerUnits="strokeWidth" id="se_marker_end_svg_43">
   <path stroke-width="10" stroke="#000000" fill="#000000" d="m100,50l-100,40l30,-40l-30,-40z"/>
  </marker>
  <marker refY="50" refX="50" markerHeight="5" markerWidth="5" viewBox="0 0 100 100" se_type="rightarrow" orient="auto" markerUnits="strokeWidth" id="se_marker_end_svg_44">
   <path stroke-width="10" stroke="#000000" fill="#000000" d="m100,50l-100,40l30,-40l-30,-40z"/>
  </marker>
 </defs>
 <g>
  <title>Layer 1</title>
  <rect id="svg_16" height="250" width="146" y="47" x="247" stroke-linecap="null" stroke-linejoin="null" stroke-dasharray="null" stroke-width="5" stroke="#000000" fill="#ff7f00"/>
  <text xml:space="preserve" text-anchor="middle" font-family="serif" font-size="24" id="svg_26" y="106" x="88" stroke-linecap="null" stroke-linejoin="null" stroke-dasharray="null" stroke-width="0" stroke="#000000" fill="#000000">Connect</text>
  <rect stroke="#000000" id="svg_1" height="236.999992" width="192.000003" y="28" x="21" stroke-width="5" fill="#007fff"/>
  <text stroke="#000000" transform="matrix(1 0 0 1.03636 0 -4.65454)" xml:space="preserve" text-anchor="middle" font-family="serif" font-size="24" id="svg_3" y="64.105261" x="104" stroke-linecap="null" stroke-linejoin="null" stroke-dasharray="null" stroke-width="0" fill="#000000">Server</text>
  <polygon stroke-width="5" stroke="#000000" points="365.69891357421875,152 333.4307861328125,196.41329956054688 281.21978759765625,179.44894409179688 281.21978759765625,124.55105590820312 333.4307861328125,107.586669921875 365.69891357421875,152 " strokeWidth="5" strokecolor="#000000" fill="#7fff00" edge="54.897885" orient="x" sides="5" shape="regularPoly" id="svg_8" cy="110" cx="42"/>
  <polygon strokeWidth="5" strokecolor="#000000" fill="#007fff" edge="0" orient="x" sides="5" shape="regularPoly" id="svg_10" cy="167" cx="105"/>
  <polygon strokeWidth="5" strokecolor="none" fill="#007fff" edge="0" orient="x" sides="5" shape="regularPoly" id="svg_11" cy="127" cx="92"/>
  <polygon strokeWidth="5" strokecolor="none" fill="#007fff" edge="0" orient="x" sides="5" shape="regularPoly" id="svg_12" cy="127" cx="96"/>
  <text xml:space="preserve" text-anchor="middle" font-family="serif" font-size="24" id="svg_13" y="160" x="321" stroke-linecap="null" stroke-linejoin="null" stroke-dasharray="null" stroke-width="0" stroke="#000000" fill="#000000">Socket</text>
  <text stroke-opacity="0" xml:space="preserve" text-anchor="middle" font-family="serif" font-size="24" id="svg_24" y="79" x="317" stroke-linecap="null" stroke-linejoin="null" stroke-dasharray="null" stroke-width="null" stroke="#000000" fill="#000000">Coroutine</text>
  <ellipse ry="41" rx="60" id="svg_33" cy="239" cx="313" stroke-linecap="null" stroke-linejoin="null" stroke-dasharray="null" stroke-width="5" stroke="#000000" fill="#ffff00"/>
  <text xml:space="preserve" text-anchor="middle" font-family="serif" font-size="24" id="svg_35" y="250" x="317" stroke-linecap="null" stroke-linejoin="null" stroke-dasharray="null" stroke-width="0" stroke="#000000" fill="#000000">Dict</text>
  <rect id="svg_36" height="245" width="205" y="32" x="422" stroke-linecap="null" stroke-linejoin="null" stroke-dasharray="null" stroke-width="5" stroke="#000000" fill="#007fff"/>
  <text xml:space="preserve" text-anchor="middle" font-family="serif" font-size="24" id="svg_37" y="73" x="514" stroke-linecap="null" stroke-linejoin="null" stroke-dasharray="null" stroke-width="0" stroke="#000000" fill="#000000">Reply</text>
  <text xml:space="preserve" text-anchor="middle" font-family="serif" font-size="24" id="svg_39" y="127" x="526" stroke-linecap="null" stroke-linejoin="null" stroke-dasharray="null" stroke-width="0" stroke="#000000" fill="#000000">dispatch</text>
  <text xml:space="preserve" text-anchor="middle" font-family="serif" font-size="24" id="svg_40" y="161" x="561" stroke-linecap="null" stroke-linejoin="null" stroke-dasharray="null" stroke-width="0" stroke="#000000" fill="#000000">content</text>
  <line stroke="#000000" marker-end="url(#se_marker_end_svg_43)" id="svg_43" y2="147.000002" x2="461" y1="223.999998" x1="378.999999" stroke-linecap="null" stroke-linejoin="null" stroke-dasharray="null" stroke-width="5" fill="none"/>
  <line marker-end="url(#se_marker_end_svg_44)" id="svg_44" y2="121" x2="467" y1="154" x1="374" stroke-linecap="null" stroke-linejoin="null" stroke-dasharray="null" stroke-width="5" stroke="#000000" fill="none"/>
  <line id="svg_45" y2="380" x2="289" y1="380" x1="288" stroke-linecap="null" stroke-linejoin="null" stroke-dasharray="null" stroke-width="5" stroke="#000000" fill="none"/>
 </g>
</svg>
The coroutine passes the dict and the socket over to the Reply's dispatch method.
}

$obj slide {
<div><svg width="640" height="480" xmlns="http://www.w3.org/2000/svg" xmlns:svg="http://www.w3.org/2000/svg">
 <!-- Created with SVG-edit - http://svg-edit.googlecode.com/ -->
 <defs>
  <marker refY="50" refX="50" markerHeight="5" markerWidth="5" viewBox="0 0 100 100" se_type="rightarrow" orient="auto" markerUnits="strokeWidth" id="se_marker_end_svg_51">
   <path stroke-width="10" stroke="#000000" fill="#000000" d="m100,50l-100,40l30,-40l-30,-40z"/>
  </marker>
 </defs>
 <g>
  <title>Layer 1</title>
  <rect id="svg_16" height="250" width="146" y="47" x="247" stroke-linecap="null" stroke-linejoin="null" stroke-dasharray="null" stroke-width="5" stroke="#000000" fill="#ff7f00"/>
  <text xml:space="preserve" text-anchor="middle" font-family="serif" font-size="24" id="svg_26" y="106" x="88" stroke-linecap="null" stroke-linejoin="null" stroke-dasharray="null" stroke-width="0" stroke="#000000" fill="#000000">Connect</text>
  <rect stroke="#000000" id="svg_1" height="236.999992" width="192.000003" y="28" x="21" stroke-width="5" fill="#007fff"/>
  <text stroke="#000000" transform="matrix(1 0 0 1.03636 0 -4.65454)" xml:space="preserve" text-anchor="middle" font-family="serif" font-size="24" id="svg_3" y="64.105261" x="104" stroke-linecap="null" stroke-linejoin="null" stroke-dasharray="null" stroke-width="0" fill="#000000">Server</text>
  <polygon strokeWidth="5" strokecolor="#000000" fill="#007fff" edge="0" orient="x" sides="5" shape="regularPoly" id="svg_10" cy="167" cx="105"/>
  <polygon strokeWidth="5" strokecolor="none" fill="#007fff" edge="0" orient="x" sides="5" shape="regularPoly" id="svg_11" cy="127" cx="92"/>
  <polygon strokeWidth="5" strokecolor="none" fill="#007fff" edge="0" orient="x" sides="5" shape="regularPoly" id="svg_12" cy="127" cx="96"/>
  <text stroke-opacity="0" xml:space="preserve" text-anchor="middle" font-family="serif" font-size="24" id="svg_24" y="79" x="317" stroke-linecap="null" stroke-linejoin="null" stroke-dasharray="null" stroke-width="null" stroke="#000000" fill="#000000">Coroutine</text>
  <rect stroke="#000000" id="svg_36" height="392.000006" width="205" y="32" x="422" stroke-linecap="null" stroke-linejoin="null" stroke-dasharray="null" stroke-width="5" fill="#007fff"/>
  <polygon stroke-width="5" stroke="#000000" points="282.69891357421875,375 250.4307861328125,419.4132995605469 198.21978759765625,402.4489440917969 198.21978759765625,347.5510559082031 250.4307861328125,330.586669921875 282.69891357421875,375 " strokeWidth="5" strokecolor="#000000" fill="#7fff00" edge="54.897885" orient="x" sides="5" shape="regularPoly" id="svg_8" cy="110" cx="42"/>
  <text xml:space="preserve" text-anchor="middle" font-family="serif" font-size="24" id="svg_13" y="384" x="239" stroke-linecap="null" stroke-linejoin="null" stroke-dasharray="null" stroke-width="0" stroke="#000000" fill="#000000">Socket</text>
  <text xml:space="preserve" text-anchor="middle" font-family="serif" font-size="24" id="svg_37" y="73" x="514" stroke-linecap="null" stroke-linejoin="null" stroke-dasharray="null" stroke-width="0" stroke="#000000" fill="#000000">Reply</text>
  <line id="svg_45" y2="380" x2="289" y1="380" x1="288" stroke-linecap="null" stroke-linejoin="null" stroke-dasharray="null" stroke-width="5" stroke="#000000" fill="none"/>
  <ellipse stroke="#000000" ry="59.000001" rx="87" id="svg_46" cy="325.000001" cx="522" stroke-linecap="null" stroke-linejoin="null" stroke-dasharray="null" stroke-width="5" fill="#ff0000"/>
  <ellipse stroke="#000000" ry="35.5" rx="83.999999" id="svg_47" cy="219.5" cx="523.999999" stroke-linecap="null" stroke-linejoin="null" stroke-dasharray="null" stroke-width="5" fill="#ff0000"/>
  <text xml:space="preserve" text-anchor="middle" font-family="serif" font-size="24" id="svg_48" y="228" x="515" stroke-linecap="null" stroke-linejoin="null" stroke-dasharray="null" stroke-width="0" stroke="#000000" fill="#000000">Mixins</text>
  <text xml:space="preserve" text-anchor="middle" font-family="serif" font-size="24" id="svg_49" y="309" x="520" stroke-linecap="null" stroke-linejoin="null" stroke-dasharray="null" stroke-width="0" stroke="#000000" fill="#000000">Mixin</text>
  <text xml:space="preserve" text-anchor="middle" font-family="serif" font-size="24" id="svg_50" y="347" x="523" stroke-linecap="null" stroke-linejoin="null" stroke-dasharray="null" stroke-width="0" stroke="#000000" fill="#000000">content</text>
  <line marker-end="url(#se_marker_end_svg_51)" id="svg_51" y2="377" x2="288" y1="350" x1="469" stroke-linecap="null" stroke-linejoin="null" stroke-dasharray="null" stroke-width="5" stroke="#000000" fill="none"/>
  <text xml:space="preserve" text-anchor="middle" font-family="serif" font-size="24" id="svg_52" y="422" x="336" stroke-linecap="null" stroke-linejoin="null" stroke-dasharray="null" stroke-width="0" stroke="#000000" fill="#000000">final output</text>
 </g>
</svg></div><div align=right;>
The reply object mixes in behaviors according to the instructions in the dict,
and uses those mixed in behaviors to generate the reply.
</div>
}

$obj slide {
<h1 style="text-align: center; vertical-align: top;">The players</h1>
<svg width="800" height="350" xmlns="http://www.w3.org/2000/svg" xmlns:svg="http://www.w3.org/2000/svg">
 <!-- Created with SVG-edit - http://svg-edit.googlecode.com/ -->

 <g>
  <title>Layer 1</title>
  <rect stroke="#000000" id="svg_1" height="236.999992" width="192.000003" y="91" x="235" stroke-width="5" fill="#007fff"/>
  <text stroke="#000000" transform="matrix(1 0 0 1.03636 0 -4.65454)" xml:space="preserve" text-anchor="middle" font-family="serif" font-size="24" id="svg_3" y="124.894737" x="318" stroke-linecap="null" stroke-linejoin="null" stroke-dasharray="null" stroke-width="0" fill="#000000">Server</text>
  <polygon strokeWidth="5" strokecolor="#000000" fill="#007fff" edge="0" orient="x" sides="5" shape="regularPoly" id="svg_10" cy="167" cx="105"/>
  <polygon strokeWidth="5" strokecolor="none" fill="#007fff" edge="0" orient="x" sides="5" shape="regularPoly" id="svg_11" cy="127" cx="92"/>
  <polygon strokeWidth="5" strokecolor="none" fill="#007fff" edge="0" orient="x" sides="5" shape="regularPoly" id="svg_12" cy="127" cx="96"/>
  <line id="svg_45" y2="380" x2="289" y1="380" x1="288" stroke-linecap="null" stroke-linejoin="null" stroke-dasharray="null" stroke-width="5" stroke="#000000" fill="none"/>
 </g>
</svg>
After the reply is returned, the socket is closed, the object is destroyed,
and the coroutine terminates. Leaving only the server, to wait for the next socket
open.
}

$obj slide {
<h1 style="text-align: center; vertical-align: top;">Simple Serverside Content Example</h1>
The Httpd module only provides a fallback hander for static server content from <b>doc_root</b>.
<p>
To generate server side content directly from a url requires modifying the Server object.
The <b>Dispatch_Local</b> method is empty by default, and intended to be replaced by the
application. If that method returns a non-empty dict, the server ends the dispatch
process, and returns that reply to the coroutine, who will in turn pass that to the
httpd::reply instance.
}


$obj slide {
<h1 style="text-align: center; vertical-align: top;">Simple Serverside Content Example</h1>
} code {# Hijack the dispatcher method on the server
oo::objdefine HTTPD {
  method Dispatch_Local data {
    # Only match up requests for demo
    if {[dict get $data REQUEST_URI] eq "demo"} {
      set reply $data
      dict set reply mixin content ::mydemo
      return $reply
    }
  }
}
}

$obj slide {
<h1 style="text-align: center; vertical-align: top;">Simple Serverside Content Example</h1>
The default behavior for an httpd::reply is to invoke a method named <b>content</b>.
It is intended that the <b>content</b> method be mixed in from some other class.
The content method populates an internal value named <b>reply_body</b>. For easy of use,
the httpd::reply class includes a <b>puts</b> method which will append to that
buffer, and mimic the heady days of CGI where we used to spew data to stdout.
}

$obj slide {
<h1 style="text-align: center; vertical-align: top;">Simple Serverside Content Example</h1>
} code {
clay::define ::mydemo {
  method content {} {
    my puts [my html_header {Hello World!}]
    my puts {<h1>Demo page</h1>}
    my puts "Generated at [clock format [clock seconds]]"
    my puts [my html_footer]
    # NOTE METHOD DOES NOT RETURN A VALUE
  }
}
}

$obj slide {
<h1 style="text-align: center; vertical-align: top;">Simpler Serverside Content Example</h1>
Httpd has a plugin to automate the process of adding simple direct Urls:
} code {
HTTPD plugin dispatch ::httpd::plugin.dict_dispatch

HTTPD uri direct * demo {} {
  my puts [my html_header {Hello World!}]
  my puts {<h1>Demo page</h1>}
  my puts "Generated at [clock format [clock seconds]]"
  my puts [my html_footer]
  # NOTE METHOD DOES NOT RETURN A VALUE
}
}

$obj slide {
<h1 style="text-align: center; vertical-align: top;">Simple Serverside Content Example</h1>
GET/POST form information is available as a dict from the FormData method.
}
$obj slide {} code {
HTTPD uri direct * time {} {
  my puts [my html_header {Hello World!}]
  set formdat [my FormData]
  my puts {<h1>Demo page</h1>}
  if {[dict exists $formdat format]} {
    set format [dict get $formdat]
  } else {
    set format "%Y-%m-%d %H:%M:%S"
  }
  my puts "Generated at [clock format [clock seconds] -format $format]"
  my puts {<form action=/[my request get REQUEST_URI]>}
  my puts "<input name=format value=\"$format\">"
  my puts {<input type=submit></form>}
  my puts [my html_footer]
}
}

$obj slide {
<h1 style="text-align: center; vertical-align: top;">Simple Serverside Content Example</h1>
The raw mime data is also available for complex request handling. In fact, the entire dict
that was built by the dispatch process is stored in the objects <b>clay</b> data structure.
} code {
HTTPD uri direct * rawmime {} {
  my puts [my html_header {Hello World!}]
  set mimetxt [my clay get mimetxt]
  my puts {<h1>Raw Mime</h1>}
  my puts "<pre>$mimetxt</pre>"
  my puts [my html_footer]
}
}

$obj slide {
<h1 style="text-align: center; vertical-align: top;">Simple Serverside Content Example</h1>
The headers for the reply can be controlled via the <b>reply</b> ensemble. CGI encoded
data from the request is available through the <b>request</b> method.
} code {
HTTPD uri direct * texttime {} {
  my reply set Content-Type text/plain
  my puts "This URI was [my request get REQUEST_URI]"
  my puts "Generated at [clock format [clock seconds]]"
}
}

$obj slide {
<h1 style="text-align: center; vertical-align: top;">.tml files</h1>
The httpd module's file server mechanism also understands Tclhttpd's old
.tml file templates.
} code {> cat ~/htdocs/demotml.tml

[my html_header {Hello World}]

<h1>Demo page</h1>
Generated at [clock format [clock seconds]]

[my html_footer]
} div {
<i>Note: the tml files are run inside of httpd::reply objects, so your templates can (but do not have to)
invoke the methods of that object.</i>
}

$obj slide {
<h1 style="text-align: center; vertical-align: top;">Rest API Example</h1>
} code {
HTTPD uri direct * restapi {} {
  # Have the reply do its own dispatching
  set URI [split [my request get REQUEST_URI] /]
  lassign [split $URI] base method uuid
  set class [find_class $method]
  if {$class eq {}} {
    # Errors will turned into the appropriate HTTP reply
    tailcall my error 404 {Not Found} {}
  }
  # Mix in a new behavior
  my clay mixinmap rest $class
  my reply set Content-Type application/json
  # Pass off control to a method brought in by the mixin
  tailcall my RestContent
}
}

$obj slide {
<h1 style="text-align: center;">Toadhttpd</h1>
The httpd module is very basic. It is intended to be a foundation to build on, not the
entire building.
<p>
To run a real web facing server requires a lot of facilities that are beyond the scope
of what an embedded web server would provide. At least a web server that is small enough
for inclusion in tcllib.
<p>
A parallel project, <b>Toadhttpd</b> extends the httpd module in tcllib into fully fledged
web server.
}

$obj slide {
<h1 style="text-align: center;">Toadhttpd</h1>
Fossil Repo: <a href="http://fossil.etoyoc.com/fossil/toadhttpd">http://fossil.etoyoc.com/fossil/toadhttpd</a>
} ul {
} li {Hardened against botnet attacks
} li {Plug-in architecture
} li {Bootstrap and jQuery Integration
} li {Sqlite Based:<ul><li>Dispatch Engine
<li>Cacheing Mechanism
<li>Logging
<li>IP Blocking
</ul>
} li {SCGI Proxy Support
} li {Built-in Fossil Mirroring Support
} /ul {
}

$obj slide {
<h1 style="text-align: center;">Q&amp;A</h1>
<p>
And if you want to play with httpd, (and you have a recent Tcllib installed)
<p>
just:
} code {
package require httpd
}

set fname [file rootname [file tail [info script]]].html
set fout [open $fname w]
puts $fout [$obj html_header {The Httpd Module and Toadhttpd}]]
puts $fout [$obj assemble]
puts $fout [$obj html_footer]
close $fout
