260806_01_ENH: multipart 데이터 ascii -> utf-8로 변경

This commit is contained in:
2026-08-06 11:13:29 +09:00
parent 1ac8dab45a
commit 0d9f1ff196
4 changed files with 18 additions and 12 deletions

View File

@@ -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

View File

@@ -178,7 +178,7 @@ ExternalApiResponse res = client.post(url, headers, jsonBody);
```java
List<ExternalApiMultipartPart> 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 인증 동작을 유지하며, 제외 패턴은 허용 패턴보다 우선합니다.

View File

@@ -4,7 +4,7 @@ plugins {
}
// 버전 변경은 여기서
def commonVer = "beta.1.5.0"
def commonVer = "beta.1.6.0"
group = 'com.kri.common'
version = commonVer

View File

@@ -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) {