Ignore:
Timestamp:
02/16/13 21:12:12 (12 years ago)
Author:
tmorgan
Message:

misc output improvements, putting more items in organized functions

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/bin/bletchley-http2py

    r28 r39  
    1515
    1616
    17 Copyright (C) 2011-2012 Virtual Security Research, LLC
     17Copyright (C) 2011-2013 Virtual Security Research, LLC
    1818Author: Timothy D. Morgan
    1919
     
    6464
    6565
    66 print('''#!/usr/bin/env python
    67 
    68 import sys
    69 # function with either Python 2.7 or 3.x
    70 try:
    71     import http.client as httpc
    72 except:
    73     import httplib as httpc
    74 ''')
    75 
    7666
    7767if '\r\n\r\n' in input_req:
     
    110100                            'accept-encoding','accept-charset',
    111101                            'connection', 'keep-alive', 'host',
    112                             'content-length']:
     102                            'content-length', 'proxy-connection']:
    113103        headers.append((name,[value]))
    114104
     
    121111            host = value
    122112
     113
     114print('''#!/usr/bin/env python
     115
     116import sys
     117# function with either Python 2.7 or 3.x
     118try:
     119    import http.client as httpc
     120except:
     121    import httplib as httpc
     122''')
     123
     124
    123125print('''
    124126# TODO: ensure the host, port, and SSL settings are correct.
     
    129131
    130132chunked_body = '\n            '.join([repr(body[i:i+40]) for i in range(0,len(body),40)])
     133if chunked_body == '':
     134    chunked_body = "''"
    131135
    132136print('''
    133 def sendRequest(connection):
     137# TODO: use "data" to supply any parameters to be included in the request
     138def sendRequest(connection, data=None):
    134139    method = %s
    135140    path = %s
     
    155160
    156161
    157 connection = None
    158 if use_ssl:
    159     connection = httpc.HTTPSConnection(host, port)
    160 else:
    161     connection = httpc.HTTPConnection(host, port)
     162def newConnection():
     163    connection = None
     164    if use_ssl:
     165        return httpc.HTTPSConnection(host, port)
     166    else:
     167        return httpc.HTTPConnection(host, port)
    162168
    163 # TODO: customize code here to retrieve what you need from the response(s)
    164 # For information on the response object's interface, see:
    165 #   http://docs.python.org/library/httplib.html#httpresponse-objects
    166169
    167 connection.connect()
    168 response = sendRequest(connection)
    169 print(response.getheaders())
    170 print(repr(response.read()))
    171 connection.close()
     170def fetch(data):
     171    ret_val = None
     172    connection = newConnection()
     173
     174    # TODO: customize code here to retrieve what you need from the response(s)
     175    # For information on the response object's interface, see:
     176    #   http://docs.python.org/library/httplib.html#httpresponse-objects
     177    response = sendRequest(connection, data)
     178    print(response.getheaders())
     179    print(repr(response.read()))
     180
     181    connection.close()
     182    return ret_val
     183
     184data = ''
     185fetch(data)
    172186''')
Note: See TracChangeset for help on using the changeset viewer.