def replace_header(headers, name, value):
 name = name.lower()
 i = 0
 result = None
 while (i < len(headers)):
  if (headers[i][0].lower() == name):
   assert (not result), ("two values for the header '%s' found" % name)
   result = headers[i][1]
   headers[i] = (name, value)
  i += 1
 if (not result):
  headers.append((name, value))
 return result

def replace_header ( headers , name , value ) : name = name . lower ( ) i = 0 result = None while ( i < len ( headers ) ) : if ( headers [ i ] [ 0 ] . lower ( ) == name ) : assert ( not result ) , ( "two values for the header '%s' found" % name ) result = headers [ i ] [ 1 ] headers [ i ] = ( name , value ) i += 1 if ( not result ) : headers . append ( ( name , value ) ) return result
updates the headers replacing the first occurance of the given name with the value provided; asserting that no further occurances happen .