Skip to content

Commit 74d1c53

Browse files
claude[bot]github-actions[bot]claude
authored
Maintenance: ImageUtils - Eliminate unnecessary HTTP request and improve performance (#121)
Co-authored-by: claude[bot] <41898282+claude[bot]@users.noreply.github.com> Co-authored-by: Claude Sonnet 4.5 <[email protected]>
1 parent 46e0efd commit 74d1c53

File tree

2 files changed

+3
-24
lines changed

2 files changed

+3
-24
lines changed

src/main/java/spring/memewikibe/common/util/ImageUtils.java

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -47,30 +47,11 @@ public static byte[] downloadBytes(String url) throws IOException {
4747
}
4848

4949
public static String detectMimeType(String imageUrl, byte[] data) {
50-
// Try by HTTP response header
51-
try {
52-
URI uri = new URI(imageUrl);
53-
HttpRequest request = HttpRequest.newBuilder()
54-
.uri(uri)
55-
.timeout(Duration.ofSeconds(5))
56-
.method("HEAD", HttpRequest.BodyPublishers.noBody())
57-
.build();
58-
59-
HttpResponse<Void> response = HTTP_CLIENT.send(request, HttpResponse.BodyHandlers.discarding());
60-
String contentType = response.headers().firstValue("Content-Type").orElse(null);
61-
if (StringUtils.hasText(contentType)) {
62-
// Content-Type might include charset, so extract only the MIME type
63-
return contentType.split(";")[0].trim();
64-
}
65-
} catch (Exception ignored) {
66-
// If HEAD request fails, continue with other methods
67-
}
68-
69-
// Try by stream content sniffing using legacy method (still works for content detection)
50+
// Prioritize byte signature analysis (fastest and most reliable)
7051
String guessed = guessContentTypeFromBytes(data);
7152
if (StringUtils.hasText(guessed)) return guessed;
72-
73-
// Fallback by extension
53+
54+
// Fallback to extension-based detection
7455
return getMimeTypeByExtension(imageUrl);
7556
}
7657

src/test/java/spring/memewikibe/common/util/ZsetConcurrencyTest.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,6 @@ void zset_is_not_thread_safe_mixed_operations() throws InterruptedException {
106106

107107
// 이 assertion은 자주 실패함 (내부 일관성이 깨짐을 증명)
108108
// dictSize와 skipSize가 다를 수 있음
109-
System.out.println("Dict size: " + dictSize + ", Skip size: " + skipSize);
110-
111109
// 최소한 하나 이상의 데이터가 있어야 함
112110
then(dictSize + skipSize).isGreaterThan(0);
113111
}

0 commit comments

Comments
 (0)