Opened 9 years ago

Closed 9 years ago

#3378 enhancement closed duplicate (duplicate)

[PATCH] web.client.HTTPPageGetter broken HTTP fix

Reported by: redbaron Owned by: redbaron
Priority: normal Milestone:
Component: web Keywords: httpclient
Cc: therve Branch:
Author:

Description (last modified by therve)

Some sites (like 108.my1.ru) sends wrong location header during 302 response. It doesn't starts with "/", i.e "location: index.html" instead of "location: /index.html" I add a small check to HTTPPageGetter so it adds "/" in front of path if it doesn't start from "/"

Here is the patch:

             self.handleStatusDefault()
             return
         url = l[0]
+        if not url.startswith('/'):
+            url = '/'+url
         if self.followRedirect:
             scheme, host, port, path = \
                 _parse(url, defaultPort=self.transport.getPeer().port)

Change History (5)

comment:1 Changed 9 years ago by redbaron

Component: coreweb
Owner: changed from Glyph to jknight

fix formatting and component.

             self.handleStatusDefault()
             return
         url = l[0]
+        if not url.startswith('/'):
+            url = '/'+url
         if self.followRedirect:
             scheme, host, port, path = \
                 _parse(url, defaultPort=self.transport.getPeer().port)

comment:2 Changed 9 years ago by therve

Description: modified (diff)

comment:3 Changed 9 years ago by therve

Cc: therve added
Owner: changed from jknight to redbaron

Thanks for your contribution. To be committed, it needs to be accompanied by an unittest. Are you willing to write one for this fix?

comment:4 Changed 9 years ago by redbaron

301 (Permamently Moved) could be a full URL ("http://new.loc/"), so my previous fix doesn' work correctly on 301 HTTP status.

New version:

             self.handleStatusDefault()
             return
         url = l[0]
+        if not url.startswith('http') and not url.startswith('/'):
+            url = '/'+url
         if self.followRedirect:
             scheme, host, port, path = \
                 _parse(url, defaultPort=self.transport.getPeer().port)

therve: I didn't do it before, so I'll make my first attempt

comment:5 Changed 9 years ago by Jean-Paul Calderone

Keywords: httpclient added
Resolution: duplicate
Status: newclosed

It could also be an url like `http.html´.

Also, #3384 is a duplicate of this. I'm closing this one, even though it's older, because there's more code attached to #3384.

Note: See TracTickets for help on using tickets.