fix(fileserver): draft-12 생성 요청의 길이 없는 본문을 첫 조각으로 저장한다 #101

Merged
donghyeon.kang merged 4 commits from fix/draft12-chunked-create-body into main 2026-11-23 15:31:56 +00:00
3 changed files with 65 additions and 9 deletions
@@ -0,0 +1,24 @@
# 업그레이드 안내 — 2026-11 draft-12 생성 요청의 길이 없는 본문
- 범위: 실험 기능 draft-12 업로드(`app.fileserver-platform.httpbis-draft12.enabled`, 기본 꺼짐)의 생성 요청
`POST /v1/experimental/draft12/uploads`가 Content-Length 없는 본문을 읽게 한 변경. 설정 키와 공개 타입은 그대로다.
기능을 켜지 않은 서비스는 바뀌는 것이 없다.
- 근거: 2026-11-22 리뷰 발견 REV-BE-0029. 같은 생성 메서드의 Javadoc이 「생성 본문을 버리면 클라이언트가 다시
보내지 않는 데이터를 잃는다」고 이미 약속했고, 같은 컨트롤러의 append와 tus는 길이 없는 본문을 이미 읽는다.
## 1. 누가 읽나
이 템플릿을 `upstream` remote로 두고 merge해 받는 파생 서비스가 읽는다. 특히 draft-12 업로드를 켜고, chunked나
HTTP/2로 생성 요청에 본문을 싣는 클라이언트를 받는 서비스다.
## 2. 바뀐 동작 (따라 할 일 없음)
| # | 바뀐 것 | 전에는 | 해당 서비스 |
| --- | --- | --- | --- |
| 1 | Content-Length가 없는 생성 요청(chunked, HTTP/2)의 본문을 업로드의 첫 조각으로 저장하고, 응답 `Upload-Offset`이 저장한 바이트 수다. 본문이 `Upload-Length`나 크기 상한을 넘으면 append와 같은 실패(413 `FILE_TOO_LARGE` 등)로 답한다. `Upload-Complete: ?1`이 같이 오면 저장한 본문으로 확정한다 | 본문을 읽지 않고 버렸고 `Upload-Offset: 0`이었다. `Upload-Complete: ?1`이면 빈 업로드를 확정하고 성공으로 답했다. 그 응답에 맞춰 생성 뒤 offset 0부터 다시 보내던 클라이언트는 이제 offset 불일치(409)를 받는다 | draft-12 업로드를 켠 서비스 |
| 2 | 본문도 Content-Length도 없는 생성 요청도 빈 append를 한 번 거친다(writer lease, staging 재연결, offset 0 커밋). 업로드 지표에 0바이트 `committed` 표본이 하나 남는다 | 생성만 하고 append를 부르지 않았다 | draft-12 업로드를 켠 서비스 |
## 3. 바뀌지 않은 것
- Content-Length가 있는 생성 본문, append(PATCH), tus 경로는 그대로다.
- 응답 헤더 이름과 오류 code 목록은 그대로다.
@@ -104,8 +104,10 @@ public class Draft12UploadController {
context));
long offset = 0;
// -1 is a body of unknown length (chunked, HTTP/2), not a missing body: read it, as append
// does, and let the use case take the negative length as unknown.
long bodyLength = request.getContentLengthLong();
if (bodyLength > 0) {
if (bodyLength != 0) {
InputStream body = request.getInputStream();
offset =
transferExecutor
@@ -12,8 +12,12 @@ import dev.caskeleton.adapter.inbound.web.fileserver.testkit.FileserverWebFixtur
import dev.caskeleton.adapter.inbound.web.fileserver.testkit.InMemoryUploadApplicationService;
import dev.caskeleton.adapter.inbound.web.fileserver.testkit.RecordingFinalizeService;
import dev.caskeleton.application.fileserver.api.UploadId;
import java.nio.charset.StandardCharsets;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.http.HttpHeaders;
import org.springframework.http.ResponseEntity;
import org.springframework.mock.web.MockHttpServletRequest;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
@@ -25,19 +29,21 @@ class Draft12ProtocolTest {
private final InMemoryUploadApplicationService uploads = new InMemoryUploadApplicationService();
private final RecordingFinalizeService finalizeService = new RecordingFinalizeService();
private Draft12UploadController controller;
private MockMvc mvc;
@BeforeEach
void setUp() {
controller =
new Draft12UploadController(
uploads.createPort(),
uploads.appendPort(),
finalizeService.port(),
FileserverWebFixtures.contextFactory(),
FileserverWebFixtures.transferExecutor(),
DRAFT);
mvc =
MockMvcBuilders.standaloneSetup(
new Draft12UploadController(
uploads.createPort(),
uploads.appendPort(),
finalizeService.port(),
FileserverWebFixtures.contextFactory(),
FileserverWebFixtures.transferExecutor(),
DRAFT))
MockMvcBuilders.standaloneSetup(controller)
.setControllerAdvice(new FileserverExceptionHandler())
.build();
}
@@ -68,6 +74,30 @@ class Draft12ProtocolTest {
assertThat(uploads.content(uploadIdOf(location))).isEqualTo("abc");
}
/**
* A chunked or HTTP/2 creation body has no Content-Length (the servlet reports -1); its bytes are
* still the first part of the upload.
*/
@Test
void aCreationBodyWithoutAContentLengthIsStoredAsTheFirstPartOfTheUpload() throws Exception {
// given
MockHttpServletRequest request =
new MockHttpServletRequest("POST", "/v1/experimental/draft12/uploads") {
@Override
public long getContentLengthLong() {
return -1;
}
};
request.setContent("abc".getBytes(StandardCharsets.UTF_8));
// when
ResponseEntity<Void> response = controller.create(request);
// then
assertThat(uploads.content(uploadIdOf(response.getHeaders().getFirst(HttpHeaders.LOCATION))))
.isEqualTo("abc");
}
/** The body's own length is the size of one part, never the size of the whole upload. */
@Test
void theFinalLengthComesFromUploadLengthRatherThanTheCreationBody() throws Exception {