MCPcopy Create free account
hub / github.com/apache/httpd / curl_parse_headerfile

Method curl_parse_headerfile

test/pyhttpd/env.py:773–825  ·  view source on GitHub ↗
(self, headerfile: str, r: ExecResult = None)

Source from the content-addressed store, hash-verified

771 return args, headerfile
772
773 def curl_parse_headerfile(self, headerfile: str, r: ExecResult = None) -> ExecResult:
774 lines = open(headerfile).readlines()
775 if r is None:
776 r = ExecResult(args=[], exit_code=0, stdout=b'', stderr=b'')
777
778 response = None
779 def fin_response(response):
780 if response:
781 r.add_response(response)
782
783 expected = ['status']
784 for line in lines:
785 if re.match(r'^$', line):
786 if 'trailer' in expected:
787 # end of trailers
788 fin_response(response)
789 response = None
790 expected = ['status']
791 elif 'header' in expected:
792 # end of header, another status or trailers might follow
793 expected = ['status', 'trailer']
794 else:
795 assert False, f"unexpected line: {line}"
796 continue
797 if 'status' in expected:
798 log.debug("reading 1st response line: %s", line)
799 m = re.match(r'^(\S+) (\d+) (.*)$', line)
800 if m:
801 fin_response(response)
802 response = {
803 "protocol": m.group(1),
804 "status": int(m.group(2)),
805 "description": m.group(3),
806 "header": {},
807 "trailer": {},
808 "body": r.outraw
809 }
810 expected = ['header']
811 continue
812 if 'trailer' in expected:
813 m = re.match(r'^([^:]+):\s*(.*)$', line)
814 if m:
815 response['trailer'][m.group(1).lower()] = m.group(2)
816 continue
817 if 'header' in expected:
818 m = re.match(r'^([^:]+):\s*(.*)$', line)
819 if m:
820 response['header'][m.group(1).lower()] = m.group(2)
821 continue
822 assert False, f"unexpected line: {line}"
823
824 fin_response(response)
825 return r
826
827 def curl_raw(self, urls, timeout=10, options=None, insecure=False,
828 force_resolve=True, no_stdout_list=False):

Callers 2

curl_rawMethod · 0.95
_endMethod · 0.80

Calls 1

ExecResultClass · 0.85

Tested by

no test coverage detected