1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 * This class allows you to prefix an existing nsIAsyncInputStream
8 * with a preloaded block of data known at construction time by wrapping the
9 * two data sources into a new nsIAsyncInputStream. Readers of the new
10 * stream initially see the preloaded data and when that has been exhausted
11 * they automatically read from the wrapped stream.
13 * It is used by nsHttpConnection when it has over buffered while reading from
14 * the HTTP input socket and accidentally consumed data that belongs to
15 * a different protocol via the HTTP Upgrade mechanism. That over-buffered
16 * data is preloaded together with the input socket to form the new input socket
17 * given to the new protocol handler.
20 #ifndef nsPreloadedStream_h__
21 #define nsPreloadedStream_h__
23 #include "nsIAsyncInputStream.h"
25 #include "mozilla/Attributes.h"
26 #include "mozilla/DataMutex.h"
31 class nsPreloadedStream final
: public nsIAsyncInputStream
,
32 public nsIInputStreamCallback
{
34 NS_DECL_THREADSAFE_ISUPPORTS
35 NS_DECL_NSIINPUTSTREAM
36 NS_DECL_NSIASYNCINPUTSTREAM
37 NS_DECL_NSIINPUTSTREAMCALLBACK
39 nsPreloadedStream(nsIAsyncInputStream
* aStream
, const char* data
,
45 nsCOMPtr
<nsIAsyncInputStream
> mStream
;
51 DataMutex
<nsCOMPtr
<nsIInputStreamCallback
>> mCallback
;
55 } // namespace mozilla