@@ -99,10 +99,12 @@ def cleanup_headers(header_lines) -> str:
99
99
This is necessary when the headers were copied from Chrome/Edge, which do not format them correctly.
100
100
If the headers are already formatted, it returns them unchanged.
101
101
"""
102
+ logging .debug ("Raw headers:\n %s" , header_lines )
102
103
if HeaderCleanup .is_already_formatted (header_lines ):
103
- print ("Headers are already formatted, returning as is." )
104
+ logging . debug ("Headers are already formatted, returning as is." )
104
105
return header_lines .strip ()
105
106
header_lines = HeaderCleanup .remove_client_variations_block (header_lines )
107
+ logging .debug ("Headers after removing ClientVariations block:\n %s" , header_lines )
106
108
lines = header_lines .splitlines ()
107
109
108
110
# Remove empty lines
@@ -118,7 +120,9 @@ def cleanup_headers(header_lines) -> str:
118
120
# Handle odd number of lines
119
121
if i < len (lines ):
120
122
result .append (lines [i ])
121
- return "\n " .join (result )
123
+ joined_result = "\n " .join (result )
124
+ logging .debug ("Formatted headers:\n %s" , joined_result )
125
+ return joined_result
122
126
123
127
@staticmethod
124
128
def remove_client_variations_block (text : str ) -> str :
@@ -160,16 +164,19 @@ def remove_client_variations_block(text: str) -> str:
160
164
@staticmethod
161
165
def is_already_formatted (header_text : str ) -> bool :
162
166
"""
163
- Returns True if the first non-empty line contains a colon followed by at least one
167
+ Returns True if either of the first two non-empty lines contains a colon followed by at least one
164
168
non-space character, indicating it's already formatted as 'Header: Value'.
165
169
"""
170
+ checked = 0
166
171
for line in header_text .splitlines ():
167
172
line = line .strip ()
168
173
if not line :
169
174
continue
175
+ checked += 1
170
176
if ":" in line :
171
177
parts = line .split (":" , 1 )
172
- return bool (parts [1 ].strip ())
173
- else :
174
- return False
178
+ if parts [1 ].strip ():
179
+ return True
180
+ if checked >= 2 :
181
+ break
175
182
return False
0 commit comments