def parseHttpHeader(data):
 raw = data.decode('iso-8859-1').splitlines()
 http_status_line = raw[0].strip()
 http_headers = {}
 http_headers_cnt = {}
 for h in raw[1:]:
  i = h.find(':')
  if (i > 0):
   key = h[:i].strip().lower()
   value = h[(i + 1):].strip()
   if (key in http_headers):
    http_headers[key] += (', %s' % value)
    http_headers_cnt[key] += 1
   else:
    http_headers[key] = value
    http_headers_cnt[key] = 1
  else:
   pass
 return (http_status_line, http_headers, http_headers_cnt)

def parseHttpHeader ( data ) : raw = data . decode ( 'iso-8859-1' ) . splitlines ( ) http_status_line = raw [ 0 ] . strip ( ) http_headers = { } http_headers_cnt = { } for h in raw [ 1 : ] : i = h . find ( ':' ) if ( i > 0 ) : key = h [ : i ] . strip ( ) . lower ( ) value = h [ ( i + 1 ) : ] . strip ( ) if ( key in http_headers ) : http_headers [ key ] += ( ', %s' % value ) http_headers_cnt [ key ] += 1 else : http_headers [ key ] = value http_headers_cnt [ key ] = 1 else : pass return ( http_status_line , http_headers , http_headers_cnt )
parses the beginning of a http request header into a pair of status line and http headers dictionary .