pub struct Body {
pub ip: Option<SocketAddr>,
/* private fields */
}Expand description
HTTP 요청 본문. 헤더만 먼저 파싱한 뒤 stream을 그대로 보유하여
핸들러가 청크 단위로 읽거나 (read_chunk / into_multipart),
전체를 한 번에 버퍼링 (bytes(cap)) 할 수 있다.
마이그레이션: 이전의 pub bytes: Vec<u8> 필드는 제거됨.
기존 코드의 req.body().bytes.as_slice() 같은 패턴은
req.body_mut().bytes(Some(N)).await? 로 교체.
Fields§
§ip: Option<SocketAddr>요청 클라이언트 IP.
Implementations§
Source§impl Body
impl Body
Sourcepub fn from_bytes(bytes: Vec<u8>, ip: Option<SocketAddr>) -> Self
pub fn from_bytes(bytes: Vec<u8>, ip: Option<SocketAddr>) -> Self
테스트/internal용: 이미 모든 바이트가 메모리에 있는 Body 생성. stream은 None이라 read_chunk는 즉시 EOF 반환.
Sourcepub fn set_max_body_size(&mut self, max: Option<usize>)
pub fn set_max_body_size(&mut self, max: Option<usize>)
옵션에서 가져온 max_body_size 설정 (parse_request 가 호출).
Sourcepub fn max_body_size(&self) -> Option<usize>
pub fn max_body_size(&self) -> Option<usize>
현재 설정된 max_body_size 캡.
Sourcepub fn content_length(&self) -> Option<usize>
pub fn content_length(&self) -> Option<usize>
Content-Length 헤더 값 (있을 때).
Sourcepub fn buffered_bytes(&self) -> &[u8] ⓘ
pub fn buffered_bytes(&self) -> &[u8] ⓘ
동기 body 바이트 접근. body가 streaming 모드인 경우, 이미 leftover에
들어와 있는 바이트만 반환 (실제 전체 body는 bytes(cap).await? 호출 필요).
from_bytes로 만든 (테스트/internal) Body에서는 전체 바이트가 leftover에 있음.
마이그레이션 가이드 (BREAKING): 이전 req.body().bytes.as_slice() 코드는
req.body().buffered_bytes() 로 임시 대체 가능. 단 streaming 모드에서는
이 메서드만으로는 데이터를 못 받으니 req.body_mut().bytes(Some(N)).await? 사용 권장.
Sourcepub fn ip(&self) -> Option<SocketAddr>
pub fn ip(&self) -> Option<SocketAddr>
클라이언트 IP.
Sourcepub async fn read_chunk(&mut self) -> Result<Option<Bytes>, SendableError>
pub async fn read_chunk(&mut self) -> Result<Option<Bytes>, SendableError>
다음 청크. EOF (Content-Length 도달 or 연결 종료) 시 None.
Sourcepub async fn bytes(
&mut self,
max: Option<usize>,
) -> Result<Vec<u8>, SendableError>
pub async fn bytes( &mut self, max: Option<usize>, ) -> Result<Vec<u8>, SendableError>
전체 body를 메모리에 버퍼링해 반환. max 초과 시 즉시 에러.
None이면 무제한 (위험 — 신뢰된 환경에서만).
Sourcepub fn into_stream(self) -> impl Stream<Item = Result<Bytes, Error>> + Send
pub fn into_stream(self) -> impl Stream<Item = Result<Bytes, Error>> + Send
body를 futures::Stream<Item = Result<Bytes, _>> 로 변환.
multer 등 streaming 파서에 직접 넘길 때 사용.
Sourcepub fn into_multipart(self, boundary: String) -> Multipart<'static>
pub fn into_multipart(self, boundary: String) -> Multipart<'static>
into_stream()을 multer Multipart로 감싸서 반환.
핸들러는 .next_field() 로 part 하나씩 청크 단위 처리 가능.