Skip to main content

Body

Struct Body 

Source
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

Source

pub fn from_bytes(bytes: Vec<u8>, ip: Option<SocketAddr>) -> Self

테스트/internal용: 이미 모든 바이트가 메모리에 있는 Body 생성. stream은 None이라 read_chunk는 즉시 EOF 반환.

Source

pub fn set_max_body_size(&mut self, max: Option<usize>)

옵션에서 가져온 max_body_size 설정 (parse_request 가 호출).

Source

pub fn max_body_size(&self) -> Option<usize>

현재 설정된 max_body_size 캡.

Source

pub fn content_length(&self) -> Option<usize>

Content-Length 헤더 값 (있을 때).

Source

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? 사용 권장.

Source

pub fn ip(&self) -> Option<SocketAddr>

클라이언트 IP.

Source

pub async fn read_chunk(&mut self) -> Result<Option<Bytes>, SendableError>

다음 청크. EOF (Content-Length 도달 or 연결 종료) 시 None.

Source

pub async fn bytes( &mut self, max: Option<usize>, ) -> Result<Vec<u8>, SendableError>

전체 body를 메모리에 버퍼링해 반환. max 초과 시 즉시 에러. None이면 무제한 (위험 — 신뢰된 환경에서만).

Source

pub fn into_stream(self) -> impl Stream<Item = Result<Bytes, Error>> + Send

body를 futures::Stream<Item = Result<Bytes, _>> 로 변환. multer 등 streaming 파서에 직접 넘길 때 사용.

Source

pub fn into_multipart(self, boundary: String) -> Multipart<'static>

into_stream()을 multer Multipart로 감싸서 반환. 핸들러는 .next_field() 로 part 하나씩 청크 단위 처리 가능.

Auto Trait Implementations§

§

impl Freeze for Body

§

impl RefUnwindSafe for Body

§

impl Send for Body

§

impl Sync for Body

§

impl Unpin for Body

§

impl UnsafeUnpin for Body

§

impl UnwindSafe for Body

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.