<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DZone Snippets: http code</title>
    <link>http://snippets.dzone.com/posts</link>
    <pubDate>Wed, 20 Aug 2008 13:27:35 GMT</pubDate>
    <description>DZone Snippets: http code</description>
    <item>
      <title>Ruby One Time Web Server</title>
      <link>http://snippets.dzone.com/posts/show/3475</link>
      <description>An interpretation of &lt;a href="http://c2.com/cgi/wiki?OneTimeWebServer"&gt;OneTimeWebServer&lt;/a&gt; in Ruby. OneTimeWebServer holds a single "page" in memory, serves it to the first visitor, and evaporates. Useful for all sorts of hijinks.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;#!/usr/local/bin/ruby&lt;br /&gt;require 'socket'&lt;br /&gt;t = STDIN.read&lt;br /&gt;while s = TCPServer.new('127.0.0.1', (ARGV[0] or 8080)).accept&lt;br /&gt;  puts s.gets&lt;br /&gt;  s.print "HTTP/1.1 200/OK\rContent-type: text/plain\r\n\r\n" + t&lt;br /&gt;  s.close&lt;br /&gt;  exit&lt;br /&gt;end&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;Usage:&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;echo "test" | ./otws.rb [optional port number, defaults to 8080]&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;Or for recursive fun:&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;cat otws.rb | ./otws.rb [optional port number, defaults to 8080]&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;</description>
      <pubDate>Wed, 07 Feb 2007 23:45:38 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/3475</guid>
      <author>jnewland (Jesse Newland)</author>
    </item>
  </channel>
</rss>
