DeepashreeAS / python-rest-client

Automatically exported from code.google.com/p/python-rest-client
0 stars 0 forks source link

adding a trailing / into uri at the end in line 140 #11

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
line 140 of restful_lib.py 

u"%s://%s%s" % (self.scheme, self.host, u'/'.join(request_path)

this will add a trailing '/' into the end of uri, even though if I specifically 
make a uri that does not 
have a '/' (i.e request is http://locahost/resource becomes 
http://localhost/resource/). This pose a 
significant problem if the server does validate uri patterns for resource. 

I'm not an expert on REST, but can you please provide explanation for adding 
that '/' ? 

Thanks, 

Original issue reported on code.google.com by phamduc...@gmail.com on 5 Mar 2010 at 2:58

GoogleCodeExporter commented 9 years ago
I don't see how u'/'.join(any_list) will add a trailing '/' to the end of the 
string. It's not what join does per se. Unless there's a '' (empty string) 
element at the end of the request_path list.

Anyways, the lines before the join:

if self.path.endswith('/'):
    request_path.append(self.path[:-1])
else:
    request_path.append(self.path)
if path.startswith('/'):
    request_path.append(path[1:])
else:
    request_path.append(path)

Could be changed for:

request_path.append(path.strip('/'))

That removes leading and trailing '/'s.

Original comment by dr.chamb...@gmail.com on 11 Oct 2010 at 6:11