Skip to main content
added 7 characters in body
Source Link
manatwork
  • 20.6k
  • 5
  • 51
  • 81

GNU Awk: 69 characters

A server itself (endlessly serves one request at a time), no library used.

Send 418 to everybody who connects (8282 69 characters):

BEGIN{while(s="/inet/tcp/80/0/0"){print"HTTP/1.1 418 I'm a teapot\n"|&s418\n"|&s
close(s)}}

Send 418 to everybody who sends something (9393 80 characters):

BEGIN{while(s="/inet/tcp/80/0/0"){s|&getline
print"HTTP/1.1 418 I'm a teapot\n"|&s418\n"|&s
close(s)}}

Send 418 to everybody who sends a valid HTTP GET request (122122 109 characters):

BEGIN{while(s="/inet/tcp/80/0/0"){s|&getline
if(/^GET \S+ HTTP\/1\.[01]$/)print"HTTP/1.1 418 I'm a teapot\n"|&s418\n"|&s
close(s)}}

GNU Awk

A server itself (endlessly serves one request at a time), no library used.

Send 418 to everybody who connects (82 characters):

BEGIN{while(s="/inet/tcp/80/0/0"){print"HTTP/1.1 418 I'm a teapot\n"|&s
close(s)}}

Send 418 to everybody who sends something (93 characters):

BEGIN{while(s="/inet/tcp/80/0/0"){s|&getline
print"HTTP/1.1 418 I'm a teapot\n"|&s
close(s)}}

Send 418 to everybody who sends a valid HTTP GET request (122 characters):

BEGIN{while(s="/inet/tcp/80/0/0"){s|&getline
if(/^GET \S+ HTTP\/1\.[01]$/)print"HTTP/1.1 418 I'm a teapot\n"|&s
close(s)}}

GNU Awk: 69 characters

A server itself (endlessly serves one request at a time), no library used.

Send 418 to everybody who connects (82 69 characters):

BEGIN{while(s="/inet/tcp/80/0/0"){print"HTTP/1.1 418\n"|&s
close(s)}}

Send 418 to everybody who sends something (93 80 characters):

BEGIN{while(s="/inet/tcp/80/0/0"){s|&getline
print"HTTP/1.1 418\n"|&s
close(s)}}

Send 418 to everybody who sends a valid HTTP GET request (122 109 characters):

BEGIN{while(s="/inet/tcp/80/0/0"){s|&getline
if(/^GET \S+ HTTP\/1\.[01]$/)print"HTTP/1.1 418\n"|&s
close(s)}}
Source Link
manatwork
  • 20.6k
  • 5
  • 51
  • 81

GNU Awk

A server itself (endlessly serves one request at a time), no library used.

Send 418 to everybody who connects (82 characters):

BEGIN{while(s="/inet/tcp/80/0/0"){print"HTTP/1.1 418 I'm a teapot\n"|&s
close(s)}}

Send 418 to everybody who sends something (93 characters):

BEGIN{while(s="/inet/tcp/80/0/0"){s|&getline
print"HTTP/1.1 418 I'm a teapot\n"|&s
close(s)}}

Send 418 to everybody who sends a valid HTTP GET request (122 characters):

BEGIN{while(s="/inet/tcp/80/0/0"){s|&getline
if(/^GET \S+ HTTP\/1\.[01]$/)print"HTTP/1.1 418 I'm a teapot\n"|&s
close(s)}}