123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293openBaseopenAsync_kernelmoduleB=Cohttp.Bodytypet=[B.t|`PipeofstringPipe.Reader.t][@@derivingsexp_of]letempty=`Emptyletof_strings=(B.of_strings:>t)letof_pipep=`Pipepletto_string=function|#B.tasbody->return(B.to_stringbody)|`Pipes->Pipe.to_lists>>|String.concatletto_string_list=function|#B.tasbody->return(B.to_string_listbody)|`Pipes->Pipe.to_listsletdrain=function#B.t->return()|`Pipep->Pipe.drainpletis_empty(body:t)=matchbodywith|#B.tasbody->return(B.is_emptybody)|`Pipepipe->(Deferred.repeat_until_finished()@@fun()->Pipe.values_availablepipe>>=function|`Eof->return(`Finishedtrue)|`Ok->(matchPipe.peekpipewith|None->return(`Finishedtrue)|Some""->(Pipe.readpipe>>|function|`Eof->`Finishedtrue|`Ok_->`Repeat())|Some_->return(`Finishedfalse)))letto_pipe=function|`Empty->Pipe.of_list[]|`Strings->Pipe.singletons|`Stringssl->Pipe.of_listsl|`Pipep->pletdisable_chunked_encoding=function|#B.tasbody->return(body,B.lengthbody)|`Pipes->Pipe.to_lists>>|funl->letbody=`Stringslinletlen=B.lengthbodyin(body,len)lettransfer_encoding=function|#B.tast->B.transfer_encodingt|`Pipe_->Cohttp.Transfer.Chunkedletof_string_liststrings=`Pipe(Pipe.of_liststrings)letmapt~f=matchtwith|#B.tast->(B.mapft:>t)|`Pipep->`Pipe(Pipe.mapp~f)letas_pipet~f=`Pipe(t|>to_pipe|>f)letto_formt=to_stringt>>|Uri.query_of_encodedletof_form?schemef=Uri.encoded_of_query?schemef|>of_stringletwrite_bodywrite_body(body:t)writer=matchbodywith|`Empty->return()|`Strings->write_bodywriters|`Stringssl->Deferred.List.itersl~f:(write_bodywriter)|`Pipep->Pipe.iterp~f:(write_bodywriter)letpipe_of_bodyread_chunkic=letopenCohttp.TransferinPipe.create_reader~close_on_exception:false(funwriter->Deferred.repeat_until_finished()(fun()->read_chunkic>>=function|Chunkbuf->(* Even if [writer] has been closed, the loop must continue reading
* from the input channel to ensure that it is left in a proper state
* for the next request to be processed (in the case of keep-alive).
*
* The only case where [writer] will be closed is when
* [Pipe.close_read] has been called on its read end. This could be
* done by a request handler to signal that it does not need to
* inspect the remainder of the body to fulfill the request.
*)Pipe.write_when_readywriter~f:(funwrite->writebuf)>>|fun_->`Repeat()|Final_chunkbuf->Pipe.write_when_readywriter~f:(funwrite->writebuf)>>|fun_->`Finished()|Done->return(`Finished())))