Skip to content

Commit fe20884

Browse files
committed
refactor(HttpURLConnectionDownloaderService): split validateConnection() into validateResponseCode() and validateContentType().
Preliminary refactoring for #1237
1 parent 7fbb2f6 commit fe20884

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

src/main/java/ru/mystamps/web/feature/series/HttpURLConnectionDownloaderService.java

+11-2
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,12 @@ public DownloadResult download(String fileUrl) {
8282
}
8383

8484
try (InputStream stream = new BufferedInputStream(conn.getInputStream())) {
85-
Code validationResult = validateConnection(conn);
85+
Code validationResult = validateResponseCode(conn);
86+
if (validationResult != Code.SUCCESS) {
87+
return DownloadResult.failed(validationResult);
88+
}
89+
90+
validationResult = validateContentType(conn);
8691
if (validationResult != Code.SUCCESS) {
8792
return DownloadResult.failed(validationResult);
8893
}
@@ -155,7 +160,7 @@ private static Code connect(HttpURLConnection conn) {
155160
}
156161
}
157162

158-
private Code validateConnection(HttpURLConnection conn) throws IOException {
163+
private Code validateResponseCode(HttpURLConnection conn) throws IOException {
159164
int status = conn.getResponseCode();
160165
if (status == HttpURLConnection.HTTP_MOVED_TEMP
161166
|| status == HttpURLConnection.HTTP_MOVED_PERM) {
@@ -169,6 +174,10 @@ private Code validateConnection(HttpURLConnection conn) throws IOException {
169174
return Code.UNEXPECTED_ERROR;
170175
}
171176

177+
return Code.SUCCESS;
178+
}
179+
180+
private Code validateContentType(HttpURLConnection conn) {
172181
String contentType = conn.getContentType();
173182

174183
// We need only the first part from "text/html; charset=UTF-8"

0 commit comments

Comments
 (0)