From 0d9f1ff19601acefa9134f82ea61e4e976ff110e Mon Sep 17 00:00:00 2001 From: kric_jspark Date: Thu, 6 Aug 2026 11:13:29 +0900 Subject: [PATCH] =?UTF-8?q?260806=5F01=5FENH:=20multipart=20=EB=8D=B0?= =?UTF-8?q?=EC=9D=B4=ED=84=B0=20ascii=20->=20utf-8=EB=A1=9C=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Agents.md | 1 + README.md | 5 ++++- build.gradle | 2 +- .../feature/http/ExternalApiClient.java | 22 ++++++++++--------- 4 files changed, 18 insertions(+), 12 deletions(-) diff --git a/Agents.md b/Agents.md index 99fbfaa..b55a902 100644 --- a/Agents.md +++ b/Agents.md @@ -176,6 +176,7 @@ Behavior: - Supports `GET`, `DELETE`, `POST`, `PUT`, `PATCH` with `String` request bodies. - Supports multipart uploads through `postMultipart` and `putMultipart`. - Multipart requests ignore caller-supplied `Content-Type` and generate `multipart/form-data` with the required boundary. +- Multipart part headers are encoded as UTF-8 so non-ASCII field names and filenames are preserved. - Responses are returned as `String` body via `ExternalApiResponse`. ### HTTP Bypass diff --git a/README.md b/README.md index 40e20d7..ba1bab1 100644 --- a/README.md +++ b/README.md @@ -178,7 +178,7 @@ ExternalApiResponse res = client.post(url, headers, jsonBody); ```java List parts = List.of( ExternalApiMultipartPart.formField("serviceCode", "demo"), - ExternalApiMultipartPart.file("file", "sample.txt", "text/plain", fileBytes) + ExternalApiMultipartPart.file("file", "한글-파일.txt", "text/plain", fileBytes) ); ExternalApiResponse res = client.postMultipart(url, headers, parts); @@ -186,6 +186,8 @@ ExternalApiResponse res = client.postMultipart(url, headers, parts); multipart 요청에서는 전달한 headers의 `Content-Type` 값을 무시하고, 필요한 boundary를 포함한 `Content-Type: multipart/form-data; boundary=...` 값을 자동 생성합니다. +multipart 파트 헤더와 텍스트 필드는 UTF-8로 인코딩하므로 한글 등 non-ASCII +파일명을 `filename="한글-파일.txt"` 형태로 손실 없이 전송합니다. 지원 메서드: @@ -763,4 +765,5 @@ Endpoint: ## 변경 이력 +- 2026-08-06: multipart 파트 헤더를 UTF-8로 인코딩하여 한글 등 non-ASCII 파일명 전송을 지원합니다. - 2026-08-04: `kri.auth.apikey.allowed-paths`와 `kri.auth.apikey.excluded-paths`를 추가했습니다. 미설정·`null`·빈 목록은 기존 전역 API Key 인증 동작을 유지하며, 제외 패턴은 허용 패턴보다 우선합니다. diff --git a/build.gradle b/build.gradle index 312c24c..022b1c2 100644 --- a/build.gradle +++ b/build.gradle @@ -4,7 +4,7 @@ plugins { } // 버전 변경은 여기서 -def commonVer = "beta.1.5.0" +def commonVer = "beta.1.6.0" group = 'com.kri.common' version = commonVer diff --git a/src/main/java/com/kri/common/feature/http/ExternalApiClient.java b/src/main/java/com/kri/common/feature/http/ExternalApiClient.java index eb48986..210a08a 100644 --- a/src/main/java/com/kri/common/feature/http/ExternalApiClient.java +++ b/src/main/java/com/kri/common/feature/http/ExternalApiClient.java @@ -136,20 +136,20 @@ public class ExternalApiClient { throw new IllegalArgumentException("parts must not contain null"); } - writeAscii(out, "--" + boundary + CRLF); - writeAscii(out, "Content-Disposition: form-data; name=\"" + headerValue(part.getName()) + "\""); + writeUtf8(out, "--" + boundary + CRLF); + writeUtf8(out, "Content-Disposition: form-data; name=\"" + headerValue(part.getName()) + "\""); if (part.getFilename() != null) { - writeAscii(out, "; filename=\"" + headerValue(part.getFilename()) + "\""); + writeUtf8(out, "; filename=\"" + headerValue(part.getFilename()) + "\""); } - writeAscii(out, CRLF); + writeUtf8(out, CRLF); if (part.getContentType() != null && !part.getContentType().isBlank()) { - writeAscii(out, "Content-Type: " + safeHeader(part.getContentType()) + CRLF); + writeUtf8(out, "Content-Type: " + safeHeader(part.getContentType()) + CRLF); } - writeAscii(out, CRLF); + writeUtf8(out, CRLF); out.write(part.content()); - writeAscii(out, CRLF); + writeUtf8(out, CRLF); } - writeAscii(out, "--" + boundary + "--" + CRLF); + writeUtf8(out, "--" + boundary + "--" + CRLF); return out.toByteArray(); } @@ -165,8 +165,10 @@ public class ExternalApiClient { }); } - private static void writeAscii(ByteArrayOutputStream out, String value) throws IOException { - out.write(value.getBytes(StandardCharsets.US_ASCII)); + private static void writeUtf8(ByteArrayOutputStream out, String value) throws IOException { + // Multipart delimiters remain byte-identical because UTF-8 is ASCII-compatible, while + // user-visible field names and filenames retain non-ASCII characters. + out.write(value.getBytes(StandardCharsets.UTF_8)); } private static String headerValue(String value) {