Skip to content

Commit 8186640

Browse files
committed
Merge pull request #31 from kamilszymanski/timeouts
fix handling of timed out HttpURLClient requests with contentType.ANY
2 parents 3cb29e9 + 9d25970 commit 8186640

File tree

3 files changed

+10
-8
lines changed

3 files changed

+10
-8
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
11
target/
2+
*.iml
3+
.idea/

src/main/java/groovyx/net/http/ParserRegistry.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -361,9 +361,11 @@ public void setDefaultParser( Closure defaultParser ) {
361361
* @param contentType
362362
* @return parser that can interpret the given response content type,
363363
* or the default parser if no parser is registered for the given
364-
* content-type. It should NOT return a null value.
364+
* content-type.
365365
*/
366366
public Closure getAt( Object contentType ) {
367+
if ( contentType == null ) return defaultParser;
368+
367369
String ct = contentType.toString();
368370
int idx = ct.indexOf( ';' );
369371
if ( idx > 0 ) ct = ct.substring( 0, idx );

src/test/groovy/groovyx/net/http/HttpURLClientTest.groovy

+5-7
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,10 @@ package groovyx.net.http
22

33
import org.junit.Ignore
44
import org.junit.Test
5-
import java.lang.AssertionError
6-
import java.io.Reader
7-
import java.io.StringReader;
85

9-
import groovy.util.XmlSlurper
10-
import groovy.util.slurpersupport.GPathResult
116
import org.apache.http.client.HttpResponseException
12-
import java.io.ByteArrayOutputStream
137
import static groovyx.net.http.ContentType.*
148
import static groovyx.net.http.Method.*
15-
import org.apache.xml.resolver.tools.CatalogResolver
169

1710
class HttpURLClientTest {
1811

@@ -237,4 +230,9 @@ class HttpURLClientTest {
237230
}
238231
catch ( IllegalArgumentException ex ) { /* Expected exception */ }
239232
}
233+
234+
@Test(expected = SocketTimeoutException)
235+
void testTimeout() {
236+
new HttpURLClient(url: 'https://www.google.com/').request(timeout: 1)
237+
}
240238
}

0 commit comments

Comments
 (0)