Skip to content

Commit 9325825

Browse files
committed
explicit timeouts for URL access
1 parent ce504a7 commit 9325825

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

org/w3c/css/util/ApplContext.java

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,15 @@ private BomEncoding(Charset c, boolean fb) {
5454
uriCharset = c;
5555
fromBom = fb;
5656
}
57+
5758
private BomEncoding(Charset c) {
5859
this(c, false);
5960
}
61+
6062
private BomEncoding() {
6163
}
6264
}
65+
6366
// charset definition of traversed URLs
6467
private HashMap<URL, BomEncoding> uricharsets = null;
6568

@@ -72,6 +75,9 @@ private BomEncoding() {
7275

7376
private ArrayList<URL> linkedmedia = new ArrayList<URL>();
7477

78+
int readTimeout = 60000; // ms
79+
int connectTimeout = 5000; // ms
80+
7581
String credential = null;
7682
String lang;
7783
Messages msgs;
@@ -322,7 +328,6 @@ public boolean getTreatVendorExtensionsAsWarnings() {
322328
* Change the behaviour of error reporting for vendor extensions.
323329
*
324330
* @param treatVendorExtensionsAsWarnings
325-
*
326331
*/
327332
public void setTreatVendorExtensionsAsWarnings(
328333
boolean treatVendorExtensionsAsWarnings) {
@@ -620,4 +625,20 @@ public void setReferrer(URL referrer) {
620625
public URL getReferrer() {
621626
return referrer;
622627
}
628+
629+
public int getReadTimeout() {
630+
return readTimeout;
631+
}
632+
633+
public void setReadTimeout(int timeout) {
634+
readTimeout = timeout;
635+
}
636+
637+
public int getConnectTimeout() {
638+
return connectTimeout;
639+
}
640+
641+
public void setConnectTimeout(int timeout) {
642+
connectTimeout = timeout;
643+
}
623644
}

org/w3c/css/util/HTTPURL.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,10 @@ private static URLConnection getConnection(URL url, URL referrer, int count,
226226
System.err.println("with [" + ac.getCredential() + ']');
227227
}
228228
}
229+
// setting timeouts
230+
urlC.setConnectTimeout(ac.getConnectTimeout());
231+
urlC.setReadTimeout(ac.getReadTimeout());
232+
229233
// avoid all kind of caches
230234
urlC.setRequestProperty("Pragma", "no-cache");
231235
urlC.setRequestProperty("Cache-Control", "no-cache, no-store");
@@ -289,7 +293,7 @@ private static URLConnection getConnection(URL url, URL referrer, int count,
289293
} catch (Exception ex) {
290294
// usually a NPE when Location is absent on a redirect.
291295
// in any case, we will count this as non existent result.
292-
throw new FileNotFoundException(url + ":" + " Error in "+status);
296+
throw new FileNotFoundException(url + ":" + " Error in " + status);
293297
} finally {
294298
httpURL.disconnect();
295299
}

0 commit comments

Comments
 (0)