getCompleteUrl method for getting the whole url (host+resource+querystring)

This commit is contained in:
Pablo Fernandez committed 2011-12-14 17:50:02 -03:00
1 parent 3f366589ea
commit 61c0b4cc9f
2 files changed
+21 -2

No files matched your search

+12 -2
View File
@@ -73,14 +73,24 @@ class Request
private void createConnection() throws IOException
{
String effectiveUrl = querystringParams.appendTo(url);
String completeUrl = getCompleteUrl();
if (connection == null)
{
System.setProperty("http.keepAlive", connectionKeepAlive ? "true" : "false");
connection = (HttpURLConnection) new URL(effectiveUrl).openConnection();
connection = (HttpURLConnection) new URL(completeUrl).openConnection();
}
}
/**
* Returns the complete url (host + resource + encoded querystring parameters).
*
* @return the complete url.
*/
public String getCompleteUrl()
{
return querystringParams.appendTo(url);
}
Response doSend() throws IOException
{
connection.setRequestMethod(this.verb.name());
@@ -73,6 +73,15 @@ public class RequestTest
assertEquals(3, request.getQueryStringParams().size());
}
@Test
public void shouldReturnTheCompleteUrl()
{
Request request = new Request(Verb.GET, "http://example.com?one=val");
request.addQuerystringParameter("two", "other val");
request.addQuerystringParameter("more", "params");
assertEquals("http://example.com?one=val&two=other%20val&more=params", request.getCompleteUrl());
}
@Test
public void shouldHandleQueryStringSpaceEncodingProperly()
{