#!/usr/bin/env python3.5

from argparse import ArgumentParser
from termcolor import colored
import requests

ap = ArgumentParser()
ap.add_argument("url", help="provide a URL to test http verbs against")
ap.add_argument("-v", "--verbose", action="store_true", help="include response headers")
args = ap.parse_args()
url = (args.url)
verbose = (args.verbose)

if ('https://' or 'http://') not in url:
	url = "https://" + url

# verbose flag will include the status code and headers in response to the request
# if no flag is specified retuns supported or not supported, or status_code for exceptions

dict = {
"GET": requests.get(url),
"POST": requests.post(url),
"PUT": requests.put(url),
"DELETE": requests.delete(url),
"OPTIONS": requests.options(url),
"TRACE": requests.request("TRACE", url)
}

def main():
	if verbose:
		for key in dict:
			print(key, "Status Code: ", dict[key].status_code, "-->", "RESPONSE HEADER: ", dict[key].headers, "\n")
	else:
		for key in dict:
			if dict[key].status_code == 200:
				print(key, "-->", colored('SUPPORTED', 'green'))
			elif dict[key].status_code == 405:
				print(key, "-->", colored('NOT SUPPORTED', 'red'))
			else:
				print(key, "-->", colored('RETURNED %d', 'yellow') % dict[key].status_code)


main()
