Changeset 47


Ignore:
Timestamp:
05/30/13 12:36:53 (11 years ago)
Author:
tmorgan
Message:

added support for binary data in request body

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/bin/bletchley-http2py

    r40 r47  
    3535import sys
    3636import argparse
     37
     38bopen = lambda f: open(f, 'rb')
    3739
    3840parser = argparse.ArgumentParser(
     
    4345    ' For more information, see: http://code.google.com/p/bletchley/wiki/Overview')
    4446parser.add_argument(
    45     'requestfile', type=open, nargs='?', default=sys.stdin,
     47    'requestfile', type=bopen, nargs='?', default=sys.stdin.buffer,
    4648    help='A file containing an HTTP request.  Defaults to stdin if omitted.')
    4749parser.add_argument(
     
    5355
    5456
    55 if '\r\n\r\n' in input_req:
    56     raw_headers,body = input_req.split('\r\n\r\n', 1)
    57 elif '\n\n' in input_req:
    58     raw_headers,body = input_req.split('\n\n', 1)
     57if b'\r\n\r\n' in input_req:
     58    raw_headers,body = input_req.split(b'\r\n\r\n', 1)
     59elif b'\n\n' in input_req:
     60    raw_headers,body = input_req.split(b'\n\n', 1)
    5961else:
    6062    raw_headers = input_req
    61     body = ''
     63    body = b''
     64
     65raw_headers = raw_headers.decode('utf-8')
    6266
    6367header_lines = raw_headers.split('\n')
     
    102106
    103107
    104 formatted_body = '\n            '.join([repr(body[i:i+40].encode()) for i in range(0,len(body),40)])
    105 if formatted_body == '':
     108formatted_body = '\n            '.join([repr(body[i:i+40]) for i in range(0,len(body),40)])
     109if formatted_body == b'':
    106110    formatted_body = "b''"
    107111
Note: See TracChangeset for help on using the changeset viewer.