Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #31 from kamilszymanski/timeouts
fix handling of timed out HttpURLClient requests with contentType.ANY
  • Loading branch information
jgritman committed May 14, 2014
2 parents 3cb29e9 + 9d25970 commit 8186640
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
2 changes: 2 additions & 0 deletions .gitignore
@@ -1 +1,3 @@
target/
*.iml
.idea/
4 changes: 3 additions & 1 deletion src/main/java/groovyx/net/http/ParserRegistry.java
Expand Up @@ -361,9 +361,11 @@ public void setDefaultParser( Closure defaultParser ) {
* @param contentType
* @return parser that can interpret the given response content type,
* or the default parser if no parser is registered for the given
* content-type. It should NOT return a null value.
* content-type.
*/
public Closure getAt( Object contentType ) {
if ( contentType == null ) return defaultParser;

String ct = contentType.toString();
int idx = ct.indexOf( ';' );
if ( idx > 0 ) ct = ct.substring( 0, idx );
Expand Down
12 changes: 5 additions & 7 deletions src/test/groovy/groovyx/net/http/HttpURLClientTest.groovy
Expand Up @@ -2,17 +2,10 @@ package groovyx.net.http

import org.junit.Ignore
import org.junit.Test
import java.lang.AssertionError
import java.io.Reader
import java.io.StringReader;

import groovy.util.XmlSlurper
import groovy.util.slurpersupport.GPathResult
import org.apache.http.client.HttpResponseException
import java.io.ByteArrayOutputStream
import static groovyx.net.http.ContentType.*
import static groovyx.net.http.Method.*
import org.apache.xml.resolver.tools.CatalogResolver

class HttpURLClientTest {

Expand Down Expand Up @@ -237,4 +230,9 @@ class HttpURLClientTest {
}
catch ( IllegalArgumentException ex ) { /* Expected exception */ }
}

@Test(expected = SocketTimeoutException)
void testTimeout() {
new HttpURLClient(url: 'https://www.google.com/').request(timeout: 1)
}
}

0 comments on commit 8186640

Please sign in to comment.