@@ -8,25 +8,25 @@ use http::header::CONTENT_LENGTH;
88use http_body_util:: { BodyExt , combinators:: UnsyncBoxBody } ;
99use std:: fmt;
1010
11- #[ cfg( all ( feature = "wasip2" , not ( feature = "wasip3" ) ) ) ]
11+ #[ cfg( wstd_p2 ) ]
1212use crate :: http:: fields:: { header_map_from_wasi, header_map_to_wasi} ;
13- #[ cfg( all ( feature = "wasip2" , not ( feature = "wasip3" ) ) ) ]
13+ #[ cfg( wstd_p2 ) ]
1414use crate :: io:: AsyncOutputStream ;
15- #[ cfg( all ( feature = "wasip2" , not ( feature = "wasip3" ) ) ) ]
15+ #[ cfg( wstd_p2 ) ]
1616use std:: future:: { Future , poll_fn} ;
17- #[ cfg( all ( feature = "wasip2" , not ( feature = "wasip3" ) ) ) ]
17+ #[ cfg( wstd_p2 ) ]
1818use std:: pin:: { Pin , pin} ;
19- #[ cfg( all ( feature = "wasip2" , not ( feature = "wasip3" ) ) ) ]
19+ #[ cfg( wstd_p2 ) ]
2020use std:: task:: { Context , Poll } ;
2121
22- #[ cfg( all ( feature = "wasip2" , not ( feature = "wasip3" ) ) ) ]
22+ #[ cfg( wstd_p2 ) ]
2323use crate :: runtime:: { AsyncPollable , Reactor , WaitFor } ;
2424
25- #[ cfg( all ( feature = "wasip2" , not ( feature = "wasip3" ) ) ) ]
25+ #[ cfg( wstd_p2 ) ]
2626use wasip2:: http:: types:: {
2727 FutureTrailers , IncomingBody as WasiIncomingBody , OutgoingBody as WasiOutgoingBody ,
2828} ;
29- #[ cfg( all ( feature = "wasip2" , not ( feature = "wasip3" ) ) ) ]
29+ #[ cfg( wstd_p2 ) ]
3030use wasip2:: io:: streams:: { InputStream as WasiInputStream , StreamError } ;
3131
3232pub mod util {
@@ -70,10 +70,10 @@ enum BodyInner {
7070 // a boxed http_body::Body impl
7171 Boxed ( UnsyncBoxBody < Bytes , Error > ) ,
7272 // a body created from a wasi-http incoming-body (p2)
73- #[ cfg( all ( feature = "wasip2" , not ( feature = "wasip3" ) ) ) ]
73+ #[ cfg( wstd_p2 ) ]
7474 Incoming ( Incoming ) ,
7575 // a body created from a p3 StreamReader
76- #[ cfg( feature = "wasip3" ) ]
76+ #[ cfg( wstd_p3 ) ]
7777 P3Stream ( P3StreamBody ) ,
7878 // a body in memory
7979 Complete {
@@ -82,7 +82,7 @@ enum BodyInner {
8282 } ,
8383}
8484
85- #[ cfg( all ( feature = "wasip2" , not ( feature = "wasip3" ) ) ) ]
85+ #[ cfg( wstd_p2 ) ]
8686impl Body {
8787 pub ( crate ) async fn send ( self , outgoing_body : WasiOutgoingBody ) -> Result < ( ) , Error > {
8888 match self . 0 {
@@ -141,7 +141,7 @@ impl Body {
141141 }
142142}
143143
144- #[ cfg( feature = "wasip3" ) ]
144+ #[ cfg( wstd_p3 ) ]
145145impl Body {
146146 pub ( crate ) fn from_p3_stream (
147147 reader : wit_bindgen:: rt:: async_support:: StreamReader < u8 > ,
@@ -161,9 +161,9 @@ impl Body {
161161 unreachable ! ( )
162162 }
163163 match self . 0 {
164- #[ cfg( all ( feature = "wasip2" , not ( feature = "wasip3" ) ) ) ]
164+ #[ cfg( wstd_p2 ) ]
165165 BodyInner :: Incoming ( i) => i. into_http_body ( ) . boxed_unsync ( ) ,
166- #[ cfg( feature = "wasip3" ) ]
166+ #[ cfg( wstd_p3 ) ]
167167 BodyInner :: P3Stream ( p3) => {
168168 // Convert p3 stream body to a boxed body
169169 let stream = AsyncInputStream :: new ( p3. reader . unwrap ( ) ) ;
@@ -198,7 +198,7 @@ impl Body {
198198 // For p3 streams, read directly using the async read method
199199 // instead of going through poll_next (which doesn't properly
200200 // persist the read future across polls, causing hangs).
201- #[ cfg( feature = "wasip3" ) ]
201+ #[ cfg( wstd_p3 ) ]
202202 if let BodyInner :: P3Stream ( p3) = prev {
203203 let mut stream = AsyncInputStream :: new ( p3. reader . unwrap ( ) ) ;
204204 let mut all_data = Vec :: new ( ) ;
@@ -221,11 +221,11 @@ impl Body {
221221 }
222222
223223 let boxed_body = match prev {
224- #[ cfg( all ( feature = "wasip2" , not ( feature = "wasip3" ) ) ) ]
224+ #[ cfg( wstd_p2 ) ]
225225 BodyInner :: Incoming ( i) => i. into_http_body ( ) . boxed_unsync ( ) ,
226226 BodyInner :: Boxed ( b) => b,
227227 BodyInner :: Complete { .. } => unreachable ! ( ) ,
228- #[ cfg( feature = "wasip3" ) ]
228+ #[ cfg( wstd_p3 ) ]
229229 BodyInner :: P3Stream ( _) => unreachable ! ( ) ,
230230 } ;
231231 let collected = boxed_body. collect ( ) . await ?;
@@ -251,9 +251,9 @@ impl Body {
251251 match & self . 0 {
252252 BodyInner :: Boxed ( b) => b. size_hint ( ) . exact ( ) ,
253253 BodyInner :: Complete { data, .. } => Some ( data. len ( ) as u64 ) ,
254- #[ cfg( all ( feature = "wasip2" , not ( feature = "wasip3" ) ) ) ]
254+ #[ cfg( wstd_p2 ) ]
255255 BodyInner :: Incoming ( i) => i. size_hint . content_length ( ) ,
256- #[ cfg( feature = "wasip3" ) ]
256+ #[ cfg( wstd_p3 ) ]
257257 BodyInner :: P3Stream ( p3) => p3. size_hint . content_length ( ) ,
258258 }
259259 }
@@ -426,28 +426,27 @@ impl fmt::Display for InvalidContentLength {
426426}
427427impl std:: error:: Error for InvalidContentLength { }
428428
429- #[ cfg( feature = "wasip3" ) ]
429+ #[ cfg( wstd_p3 ) ]
430430struct P3StreamBody {
431431 reader : Option < wit_bindgen:: rt:: async_support:: StreamReader < u8 > > ,
432432 size_hint : BodyHint ,
433433}
434434
435- #[ cfg( feature = "wasip3" ) ]
435+ #[ cfg( wstd_p3 ) ]
436436impl fmt:: Debug for P3StreamBody {
437437 fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
438438 f. debug_struct ( "P3StreamBody" ) . finish ( )
439439 }
440440}
441441
442-
443- #[ cfg( all( feature = "wasip2" , not( feature = "wasip3" ) ) ) ]
442+ #[ cfg( wstd_p2) ]
444443#[ derive( Debug ) ]
445444struct Incoming {
446445 body : WasiIncomingBody ,
447446 size_hint : BodyHint ,
448447}
449448
450- #[ cfg( all ( feature = "wasip2" , not ( feature = "wasip3" ) ) ) ]
449+ #[ cfg( wstd_p2 ) ]
451450impl Incoming {
452451 fn into_http_body ( self ) -> IncomingBody {
453452 IncomingBody :: new ( self . body , self . size_hint )
@@ -482,14 +481,14 @@ impl Incoming {
482481 }
483482}
484483
485- #[ cfg( all ( feature = "wasip2" , not ( feature = "wasip3" ) ) ) ]
484+ #[ cfg( wstd_p2 ) ]
486485#[ derive( Debug ) ]
487486pub struct IncomingBody {
488487 state : Option < Pin < Box < IncomingBodyState > > > ,
489488 size_hint : BodyHint ,
490489}
491490
492- #[ cfg( all ( feature = "wasip2" , not ( feature = "wasip3" ) ) ) ]
491+ #[ cfg( wstd_p2 ) ]
493492impl IncomingBody {
494493 fn new ( body : WasiIncomingBody , size_hint : BodyHint ) -> Self {
495494 Self {
@@ -508,7 +507,7 @@ impl IncomingBody {
508507 }
509508}
510509
511- #[ cfg( all ( feature = "wasip2" , not ( feature = "wasip3" ) ) ) ]
510+ #[ cfg( wstd_p2 ) ]
512511impl HttpBody for IncomingBody {
513512 type Data = Bytes ;
514513 type Error = Error ;
@@ -564,7 +563,7 @@ impl HttpBody for IncomingBody {
564563 }
565564}
566565
567- #[ cfg( all ( feature = "wasip2" , not ( feature = "wasip3" ) ) ) ]
566+ #[ cfg( wstd_p2 ) ]
568567pin_project_lite:: pin_project! {
569568 #[ project = IBSProj ]
570569 #[ derive( Debug ) ]
@@ -583,18 +582,18 @@ pin_project_lite::pin_project! {
583582 }
584583}
585584
586- #[ cfg( all ( feature = "wasip2" , not ( feature = "wasip3" ) ) ) ]
585+ #[ cfg( wstd_p2 ) ]
587586#[ derive( Debug ) ]
588587struct BodyState {
589588 wait : Option < Pin < Box < WaitFor > > > ,
590589 subscription : Option < AsyncPollable > ,
591590 stream : WasiInputStream ,
592591}
593592
594- #[ cfg( all ( feature = "wasip2" , not ( feature = "wasip3" ) ) ) ]
593+ #[ cfg( wstd_p2 ) ]
595594const MAX_FRAME_SIZE : u64 = 64 * 1024 ;
596595
597- #[ cfg( all ( feature = "wasip2" , not ( feature = "wasip3" ) ) ) ]
596+ #[ cfg( wstd_p2 ) ]
598597impl BodyState {
599598 fn poll_frame (
600599 mut self : Pin < & mut Self > ,
@@ -639,15 +638,15 @@ impl BodyState {
639638 }
640639}
641640
642- #[ cfg( all ( feature = "wasip2" , not ( feature = "wasip3" ) ) ) ]
641+ #[ cfg( wstd_p2 ) ]
643642#[ derive( Debug ) ]
644643struct TrailersState {
645644 wait : Option < Pin < Box < WaitFor > > > ,
646645 subscription : Option < AsyncPollable > ,
647646 future_trailers : FutureTrailers ,
648647}
649648
650- #[ cfg( all ( feature = "wasip2" , not ( feature = "wasip3" ) ) ) ]
649+ #[ cfg( wstd_p2 ) ]
651650impl TrailersState {
652651 fn new ( future_trailers : FutureTrailers ) -> Self {
653652 Self {
0 commit comments