Created
August 3, 2016 08:44
-
-
Save mrThe/97c782561e27cf5065d66656db205231 to your computer and use it in GitHub Desktop.
Simple http race condition helper. It can be more usable, but no one cares.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'socket' | |
def create_request(data) | |
host = '127.0.0.1' | |
port = 80 | |
request = '' | |
request << "POST /something.json HTTP/1.1\r\n" | |
request << "Host: localhost\r\n" | |
# add here your headers | |
request << "Content-Length: #{data.size}\r\n" | |
socket = TCPSocket.open(host,port) | |
socket.print(request) | |
socket.print("\r\n") | |
# socket.print(data) | |
socket | |
end | |
pew_pew = false | |
tt = [] | |
ss = [] | |
50.times do |i| | |
tt << Thread.new do | |
data = "post data here" | |
socket = create_request(data) | |
ss << socket | |
puts "Thread #{i} done!" | |
sleep 0.00001 until pew_pew | |
socket.print(data) | |
socket.print("\r\n\r\n") | |
socket.flush | |
puts "\n\n\n===========" | |
puts socket.read | |
puts "===========\n\n\n" | |
end | |
end | |
# run it on irb, then wait for all threads spawn, then set pew_pew to true: `pew_pew = true`. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment