-
-
Save progrium/1362014 to your computer and use it in GitHub Desktop.
parse_http for nc http
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
# writes host to a host file | |
nc -l -p 9998 -c "./parse_http>/tmp/cgi;. /tmp/cgi>/dev/null && echo $HTTP_HOST > host" | |
# pipemill the request body | |
nc -l -p 9998 -c "./parse_http>/tmp/cgi;. /tmp/cgi | while read line; do something; done" | |
# route on the path | |
# uhh, well, sure, just use if on $HTTP_PATHINFO |
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
#!/usr/bin/ruby | |
first_line = true | |
headers = true | |
ARGF.each_line do |line| | |
if first_line | |
method, uri, version = line.split(' ') | |
path, query_string = uri.split('?', 2) | |
puts "REQUEST_METHOD=#{method}" | |
puts "PATH_INFO=#{path}" | |
puts "QUERY_STRING=?#{query_string}" | |
first_line = false | |
else | |
if headers | |
if line.length > 2 | |
name, value = line.split(':', 2) << '' | |
puts "HTTP_#{name.gsub('-', '_').upcase}=\"#{value.strip}\"" | |
else | |
headers = false | |
end | |
else | |
puts "echo #{line}" | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment