68
19
As we all should know, there's a HTTP status code 418: I'm a teapot.
Your mission, should you choose to accept it, is to use your creativitea and write the smallest possible server that responds with the above status code to any and every HTTP request made to it.
Standard loopholes apply, including
Fetching the desired output from an external source
This includes doing an HTTP request to fetch the page with the question and extracting a solution from that page. This was mildly amusing back in 2011, but now is derivative and uninteresting.
Meaning you cannot simply redirect the request to another server to have it return the response.
Addressing some confusion about server functionality:
Your server can do anything (or nothing) while no HTTP request is made to it as long as it replies with the correct response once a HTTP request is made.
@Luminous It was created for Internet Teapots, and those now exist, so... – wizzwizz4 – 2016-03-20T07:29:27.937
@wizzwizz4 HTeaTeaPot – mbomb007 – 2017-02-28T20:57:18.060
2@mbomb007 Hyper Tea Transfer Pot. – wizzwizz4 – 2017-02-28T22:19:20.977
1
How much use can we make of external libraries? (e.g. using express for a node.js server)
– Martin Ender – 2014-11-19T13:02:04.5031Should we take the “HTTP” in “any and every HTTP request” literally? I mean, if the request is not HTTP request (or even no request at all, so the client just connects and says nothing), should the server still reply or not? – manatwork – 2014-11-19T13:02:28.667
Is it strictly HTTP when the server immediately sends a response without waiting for the request? (As most of the answers here are doing.) – billpg – 2014-11-19T15:25:47.883
15to each and every http request? Surely just ones to a coffee: URI? – dave – 2014-11-19T18:24:16.570
3May we assume we already have root privileges? (e.g. bind() to port 80 is ok) – Digital Trauma – 2014-11-19T20:03:39.970
1@MartinBüttner All libraries are welcome, as many languages have such functionality built-in. – Nit – 2014-11-19T23:26:28.943
2@DigitalTrauma Yes, you can assume escalated privileges for your server. – Nit – 2014-11-19T23:26:50.730
1@manatwork Responding to non-HTTP requests is undefined behavior, meaning your program can do anything (or nothing). As long as it replies with the correct response once a HTTP request is made. – Nit – 2014-11-19T23:40:00.933
@billpg See the comment above. – Nit – 2014-11-19T23:49:35.283
1Most of the answers below do not output the required newlines to signal the end of HTTP response; most browsers would just treat them as prematurely terminated connection. – Lie Ryan – 2014-11-20T00:39:17.597
@LieRyan Feel free to point out the error to the related answers. – Nit – 2014-11-20T01:11:38.327
Would be something like a config line in httpd.conf ok? – Knerd – 2014-11-20T15:39:53.430
4@Knerd I'm leaning on the no side, you're not writing a program, you're simply configuring one. – Nit – 2014-11-20T17:10:15.487
2omg. With the IOT coming around, this status code may have an actual reason to exist! – Luminous – 2014-11-20T18:48:33.290
2creativitea? iron druid? :D – kukac67 – 2014-11-20T19:13:18.817
@Pietu1998 https://gist.github.com/red-green/474a370f7c3273403827 mine is better
– TheDoctor – 2014-11-26T01:51:59.827