Skip to content

Commit cd9912b

Browse files
committed
improving DefaultSchemaClient to follow Location redirects
1 parent 51915dd commit cd9912b

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

core/src/main/java/org/everit/json/schema/loader/internal/DefaultSchemaClient.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import java.io.InputStream;
55
import java.io.UncheckedIOException;
66
import java.net.URL;
7+
import java.net.URLConnection;
78

89
import org.everit.json.schema.loader.SchemaClient;
910

@@ -15,7 +16,13 @@ public class DefaultSchemaClient implements SchemaClient {
1516
@Override
1617
public InputStream get(final String url) {
1718
try {
18-
return (InputStream) new URL(url).getContent();
19+
URL u = new URL(url);
20+
URLConnection conn = u.openConnection();
21+
String location = conn.getHeaderField("Location");
22+
if (location != null) {
23+
return get(location);
24+
}
25+
return (InputStream) conn.getContent();
1926
} catch (IOException e) {
2027
throw new UncheckedIOException(e);
2128
}

0 commit comments

Comments
 (0)