Python3.9的http.client.py下的HTTPMessage类中的方法getallmatchingheaders的bug修复建议详解编程语言

在官方网站已经提交相关issue,不过目前看好像还没有修复。具体的bug位置为:

http文件夹下的client.py文件,代码位置为:类HTTPMessage下的方法getallmatchingheaders

源代码如下:

    def getallmatchingheaders(self, name): 
        """Find all header lines matching a given header name. 
 
        Look through the list of headers and find all lines matching a given 
        header name (and their continuation lines).  A list of the lines is 
        returned, without interpretation.  If the header does not occur, an 
        empty list is returned.  If the header occurs multiple times, all 
        occurrences are returned.  Case is not important in the header name. 
 
        """ 
        name = name.lower() + ':'  
        n = len(name) 
        lst = [] 
        hit = 0 
        for line in self.keys():  
            if line[:n].lower() == name: 
                hit = 1 
            elif not line[:1].isspace(): 
                hit = 0 
            if hit: 
                lst.append(line)  
        return lst 

 修改后代码如下:

 1     def getallmatchingheaders(self, name): 
 2         """Find all header lines matching a given header name. 
 3  
 4         Look through the list of headers and find all lines matching a given 
 5         header name (and their continuation lines).  A list of the lines is 
 6         returned, without interpretation.  If the header does not occur, an 
 7         empty list is returned.  If the header occurs multiple times, all 
 8         occurrences are returned.  Case is not important in the header name. 
 9  
10         """ 
11         name = name.lower()   
12         n = len(name) 
13         lst = [] 
14         hit = 0 
15         for line,value in self.items():  
16             if line[:n].lower() == name: 
17                 hit = 1 
18             elif not line[:1].isspace(): 
19                 hit = 0 
20             if hit: 
21                 lst.append(line+':'+value)  
22         return lst

原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/tech/pnotes/19728.html

(0)
上一篇 2021年7月19日 22:25
下一篇 2021年7月19日 22:25

相关推荐

发表回复

登录后才能评论