SHARE
TWEET

Untitled

a guest Aug 25th, 2019 93 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/usr/bin/env python3
  2.  
  3. import email
  4. import io
  5. import sys
  6.  
  7.  
  8. def run():
  9.     request_text = sys.stdin.read()
  10.     request_line, headers_raw = request_text.strip().split('\n', 1)
  11.     message = email.message_from_file(io.StringIO(headers_raw))
  12.     headers = dict(message.items())
  13.     headers_inline = [f"-H '{header_key}: {header_value}'"
  14.                       for header_key, header_value in headers.items()]
  15.     method, url, _ = request_line.split(' ')
  16.     command_parts = [f"curl -X{method}"] + headers_inline + [f"-d '{message.get_payload()}'", f"'{url}'"]
  17.     print(" ".join(command_parts))
  18.  
  19.  
  20. if __name__ == '__main__':
  21.     run()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top