2013-10-10 04:21:49 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
#ifndef mozilla_net_Http2Push_Internal_h
|
|
|
|
#define mozilla_net_Http2Push_Internal_h
|
|
|
|
|
2015-05-12 20:45:15 +03:00
|
|
|
// HTTP/2 - RFC 7540
|
|
|
|
// https://www.rfc-editor.org/rfc/rfc7540.txt
|
|
|
|
|
2013-10-10 04:21:49 +04:00
|
|
|
#include "Http2Session.h"
|
|
|
|
#include "Http2Stream.h"
|
|
|
|
|
|
|
|
#include "mozilla/Attributes.h"
|
|
|
|
#include "mozilla/TimeStamp.h"
|
2015-11-09 05:28:05 +03:00
|
|
|
#include "mozilla/UniquePtr.h"
|
2013-10-10 04:21:49 +04:00
|
|
|
#include "nsHttpRequestHead.h"
|
|
|
|
#include "nsILoadGroup.h"
|
2016-04-21 17:59:17 +03:00
|
|
|
#include "nsIRequestContext.h"
|
2013-10-10 04:21:49 +04:00
|
|
|
#include "nsString.h"
|
|
|
|
#include "PSpdyPush.h"
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace net {
|
|
|
|
|
|
|
|
class Http2PushTransactionBuffer;
|
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
class Http2PushedStream final : public Http2Stream
|
2013-10-10 04:21:49 +04:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
Http2PushedStream(Http2PushTransactionBuffer *aTransaction,
|
|
|
|
Http2Session *aSession,
|
|
|
|
Http2Stream *aAssociatedStream,
|
|
|
|
uint32_t aID);
|
|
|
|
virtual ~Http2PushedStream() {}
|
|
|
|
|
|
|
|
bool GetPushComplete();
|
2014-10-21 22:35:41 +04:00
|
|
|
|
|
|
|
// The consumer stream is the synthetic pull stream hooked up to this push
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual Http2Stream *GetConsumerStream() override { return mConsumerStream; };
|
2014-10-21 22:35:41 +04:00
|
|
|
|
|
|
|
void SetConsumerStream(Http2Stream *aStream);
|
2013-10-10 04:21:49 +04:00
|
|
|
bool GetHashKey(nsCString &key);
|
|
|
|
|
|
|
|
// override of Http2Stream
|
2015-03-21 19:28:04 +03:00
|
|
|
nsresult ReadSegments(nsAHttpSegmentReader *, uint32_t, uint32_t *) override;
|
|
|
|
nsresult WriteSegments(nsAHttpSegmentWriter *, uint32_t, uint32_t *) override;
|
2015-12-09 21:11:04 +03:00
|
|
|
void AdjustInitialWindow() override;
|
2013-10-10 04:21:49 +04:00
|
|
|
|
2016-04-21 17:59:17 +03:00
|
|
|
nsIRequestContext *RequestContext() override { return mRequestContext; };
|
2013-10-10 04:21:49 +04:00
|
|
|
void ConnectPushedStream(Http2Stream *consumer);
|
|
|
|
|
2014-10-21 22:35:41 +04:00
|
|
|
bool TryOnPush();
|
2016-02-19 01:30:46 +03:00
|
|
|
static bool TestOnPush(Http2Stream *consumer);
|
2014-10-21 22:35:41 +04:00
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual bool DeferCleanup(nsresult status) override;
|
2013-10-10 04:21:49 +04:00
|
|
|
void SetDeferCleanupOnSuccess(bool val) { mDeferCleanupOnSuccess = val; }
|
|
|
|
|
|
|
|
bool IsOrphaned(TimeStamp now);
|
2014-10-21 22:35:41 +04:00
|
|
|
void OnPushFailed() { mDeferCleanupOnPush = false; mOnPushFailed = true; }
|
2013-10-10 04:21:49 +04:00
|
|
|
|
|
|
|
nsresult GetBufferedData(char *buf, uint32_t count, uint32_t *countWritten);
|
|
|
|
|
|
|
|
// overload of Http2Stream
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual bool HasSink() override { return !!mConsumerStream; }
|
2013-10-10 04:21:49 +04:00
|
|
|
|
2014-10-21 22:35:41 +04:00
|
|
|
nsCString &GetRequestString() { return mRequestString; }
|
|
|
|
|
2013-10-10 04:21:49 +04:00
|
|
|
private:
|
|
|
|
|
|
|
|
Http2Stream *mConsumerStream; // paired request stream that consumes from
|
|
|
|
// real http/2 one.. null until a match is made.
|
|
|
|
|
2016-04-21 17:59:17 +03:00
|
|
|
nsCOMPtr<nsIRequestContext> mRequestContext;
|
2013-10-10 04:21:49 +04:00
|
|
|
|
2014-10-21 22:35:41 +04:00
|
|
|
nsAHttpTransaction *mAssociatedTransaction;
|
|
|
|
|
2013-10-10 04:21:49 +04:00
|
|
|
Http2PushTransactionBuffer *mBufferedPush;
|
|
|
|
mozilla::TimeStamp mLastRead;
|
|
|
|
|
|
|
|
nsCString mHashKey;
|
|
|
|
nsresult mStatus;
|
|
|
|
bool mPushCompleted; // server push FIN received
|
|
|
|
bool mDeferCleanupOnSuccess;
|
2014-10-21 22:35:41 +04:00
|
|
|
|
|
|
|
// mDeferCleanupOnPush prevents Http2Session::CleanupStream() from
|
|
|
|
// destroying the push stream on an error code during the period between
|
|
|
|
// when we need to do OnPush() on another thread and the time it takes
|
|
|
|
// for that event to create a synthetic pull stream attached to this
|
|
|
|
// object. That synthetic pull will become mConsuemerStream.
|
|
|
|
// Ths is essentially a delete protecting reference.
|
|
|
|
bool mDeferCleanupOnPush;
|
|
|
|
bool mOnPushFailed;
|
|
|
|
nsCString mRequestString;
|
|
|
|
|
2013-10-10 04:21:49 +04:00
|
|
|
};
|
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
class Http2PushTransactionBuffer final : public nsAHttpTransaction
|
2013-10-10 04:21:49 +04:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
NS_DECL_NSAHTTPTRANSACTION
|
|
|
|
|
|
|
|
Http2PushTransactionBuffer();
|
|
|
|
|
|
|
|
nsresult GetBufferedData(char *buf, uint32_t count, uint32_t *countWritten);
|
|
|
|
void SetPushStream(Http2PushedStream *stream) { mPushStream = stream; }
|
|
|
|
|
|
|
|
private:
|
2014-06-24 20:36:44 +04:00
|
|
|
virtual ~Http2PushTransactionBuffer();
|
|
|
|
|
2013-10-10 04:21:49 +04:00
|
|
|
const static uint32_t kDefaultBufferSize = 4096;
|
|
|
|
|
|
|
|
nsresult mStatus;
|
|
|
|
nsHttpRequestHead *mRequestHead;
|
|
|
|
Http2PushedStream *mPushStream;
|
|
|
|
bool mIsDone;
|
|
|
|
|
2015-11-09 05:28:05 +03:00
|
|
|
UniquePtr<char[]> mBufferedHTTP1;
|
2013-10-10 04:21:49 +04:00
|
|
|
uint32_t mBufferedHTTP1Size;
|
|
|
|
uint32_t mBufferedHTTP1Used;
|
|
|
|
uint32_t mBufferedHTTP1Consumed;
|
|
|
|
};
|
|
|
|
|
2015-07-13 18:25:42 +03:00
|
|
|
} // namespace net
|
2013-10-10 04:21:49 +04:00
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif // mozilla_net_Http2Push_Internal_h
|