Skip to content

Instantly share code, notes, and snippets.

@zmalltalker
Created July 5, 2013 11:40
Show Gist options
  • Save zmalltalker/5933987 to your computer and use it in GitHub Desktop.
Save zmalltalker/5933987 to your computer and use it in GitHub Desktop.
HTTP 100 continue with wget
require "socket"
server = TCPServer.new("0.0.0.0", 9999)
count = 0
loop do
count = count + 1
client = server.accept
req = client.readline
client.readline
if count > 3
client.puts "HTTP/1.1 200 OK"
client.puts "Content-Type: text/plain"
client.puts "Content-Length: 10"
client.puts "Connection: close"
client.puts
client.puts "1234567890"
count = 0
else
client.puts "HTTP/1.1 100 CONTINUE"
client.puts "Content-Type: text/plain"
client.puts "Content-Length: 0"
client.puts "Connection: close"
client.puts
end
client.close_write
end
@zmalltalker
Copy link
Author

Combining this with wget localhost:9999 will cause wget to keep trying until it receives a response.

Change 100 CONTINUE to 202 CREATED and it won't.

@judofyr
Copy link

judofyr commented Jul 5, 2013

Cool. What's the use-case here? Why can't you just hold onto the connection?

BTW: 100 Continue will never have a body, so it should work without Content-Length.

@zmalltalker
Copy link
Author

The use case was that an app responded to an expensive request (generate a git tarball} by putting a message on a queue and returning an empty 202 response. Wget would consider this empty response a success. Http 100 would make it retry.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment