import { fromStreamingXhr } from './from_streaming_xhr' ; export interface FetchStreamingParams { url : string ; headers ? : Record < string , string > ; method ? : 'GET' | 'POST' ; body ? : string ; } /**
 * Sends an AJAX request to the server, and processes the result as a
 * streaming HTTP/1 response. Streams data as text through observable.
 */ export function fetchStreaming ( { url , headers = { } , method = 'POST' , body = '' , } ) { const xhr = new window . XMLHttpRequest ( ) ; xhr . open ( method , url ) ; xhr . withCredentials = true ; Object . entries ( headers ) . forEach ( ( [ k , v ] ) => xhr . setRequestHeader ( k , v ) ) ; const stream = fromStreamingXhr ( xhr ) ; xhr . send ( body ) ; return { xhr , stream , } ; }