зеркало из https://github.com/mozilla/pjs.git
nsIHTTPConnection.h - extended the nsIHTTPConnection interface so the internal streamlistener is accessible.
nsHTTPConnection.cpp - GetInputStream now uses a syncStream listener. nsHTTPConnection.h - api update to support new nsIHTTPConnection interface and added nsIStreamListener member. nsHTTPResponseListener.cpp - added code to push data through the pipe
This commit is contained in:
Родитель
58fd17b9fc
Коммит
7a37a63b8f
|
@ -1,76 +0,0 @@
|
|||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#ifndef _nsIHTTPConnection_h_
|
||||
#define _nsIHTTPConnection_h_
|
||||
|
||||
#include "nsIProtocolConnection.h"
|
||||
#include "nsHTTPEnums.h"
|
||||
class nsIHTTPEventSink;
|
||||
/*
|
||||
The nsIHTTPConnection class is the interface to an intance
|
||||
of the HTTP that acts on a per URL basis. This used to be the
|
||||
nsIHTTPInstance class when nsIProtocolConnection used to be
|
||||
correctly called nsIProtocolInstance. If this confuses you
|
||||
don't blame me :-)
|
||||
|
||||
-Gagan Saksena 03/06/99
|
||||
*/
|
||||
|
||||
class nsIHTTPConnection : public nsIProtocolConnection
|
||||
{
|
||||
|
||||
public:
|
||||
|
||||
/*
|
||||
Request functions-
|
||||
These functions set/get parameters on the outbound request and may only
|
||||
be set before Load() function gets called. Calling them after
|
||||
the Load() method will result in a NS_ERROR_ALREADY_CONNECTED
|
||||
*/
|
||||
NS_IMETHOD GetRequestHeader(const char* i_Header, const char* *o_Value) const = 0;
|
||||
NS_IMETHOD SetRequestHeader(const char* i_Header, const char* i_Value) = 0;
|
||||
|
||||
NS_IMETHOD SetRequestMethod(HTTPMethod i_Method=HM_GET) = 0;
|
||||
|
||||
/*
|
||||
Response funtions. A call to any of these implicitly calls Load() on this
|
||||
protocol instance.
|
||||
*/
|
||||
NS_IMETHOD GetResponseHeader(const char* i_Header, const char* *o_Value) = 0;
|
||||
|
||||
NS_IMETHOD GetResponseStatus(PRInt32* o_Status) = 0;
|
||||
|
||||
NS_IMETHOD GetResponseString(const char* *o_String) = 0;
|
||||
|
||||
NS_IMETHOD EventSink(nsIHTTPEventSink* *o_EventSink) const = 0;
|
||||
|
||||
static const nsIID& GetIID() {
|
||||
// {843D1020-D0DF-11d2-B013-006097BFC036}
|
||||
static const nsIID NS_IHTTPConnection_IID =
|
||||
{ 0x843d1020, 0xd0df, 0x11d2, { 0xb0, 0x13, 0x0, 0x60, 0x97, 0xbf, 0xc0, 0x36 } };
|
||||
|
||||
return NS_IHTTPConnection_IID;
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
//Possible errors
|
||||
//#define NS_ERROR_WHATEVER NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_NETWORK, 400);
|
||||
|
||||
#endif /* _nsIHTTPConnection_h_ */
|
|
@ -36,7 +36,8 @@ nsHTTPConnection::nsHTTPConnection(
|
|||
m_pHandler(dont_QueryInterface(i_Handler)),
|
||||
m_pEventSink(dont_QueryInterface(i_HTTPEventSink)),
|
||||
m_pResponse(nsnull),
|
||||
m_pEventQ(dont_QueryInterface(i_EQ))
|
||||
m_pEventQ(dont_QueryInterface(i_EQ)),
|
||||
m_pResponseDataListener(nsnull)
|
||||
|
||||
{
|
||||
//TODO think if we need to make a copy of the URL and keep it here
|
||||
|
@ -67,6 +68,8 @@ nsHTTPConnection::~nsHTTPConnection()
|
|||
delete m_pResponse;
|
||||
m_pResponse = 0;
|
||||
}
|
||||
|
||||
NS_IF_RELEASE(m_pResponseDataListener);
|
||||
}
|
||||
|
||||
NS_IMPL_ADDREF(nsHTTPConnection);
|
||||
|
@ -92,12 +95,26 @@ nsHTTPConnection::Resume(void)
|
|||
NS_METHOD
|
||||
nsHTTPConnection::GetInputStream(nsIInputStream* *o_Stream)
|
||||
{
|
||||
#if 0
|
||||
nsresult rv;
|
||||
|
||||
if (!m_bConnected)
|
||||
Open();
|
||||
|
||||
nsIInputStream* inStr; // this guy gets passed out to the user
|
||||
rv = NS_NewSyncStreamListener(&m_pResponseDataListener, &inStr);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
*o_Stream = inStr;
|
||||
return NS_OK;
|
||||
|
||||
#else
|
||||
|
||||
if (m_pResponse)
|
||||
return m_pResponse->GetInputStream(o_Stream);
|
||||
NS_ERROR("No response!");
|
||||
return NS_OK; // change to error ? or block till response is set up?
|
||||
#endif // if 0
|
||||
|
||||
}
|
||||
|
||||
|
@ -212,7 +229,7 @@ nsHTTPConnection::Open(void)
|
|||
#endif // jud
|
||||
|
||||
rv = m_pHandler->GetTransport(host, unsignedPort, &temp);
|
||||
if (temp)
|
||||
if (NS_SUCCEEDED(rv) && temp)
|
||||
{
|
||||
m_pRequest->SetTransport(temp);
|
||||
|
||||
|
@ -291,3 +308,13 @@ nsHTTPConnection::GetURL(nsIURL* *o_URL) const
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsHTTPConnection::GetResponseDataListener(nsIStreamListener* *aListener)
|
||||
{
|
||||
if (m_pResponseDataListener) {
|
||||
*aListener = m_pResponseDataListener;
|
||||
NS_ADDREF(m_pResponseDataListener);
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
|
|
@ -99,6 +99,9 @@ public:
|
|||
|
||||
NS_IMETHOD SetResponse(nsHTTPResponse* i_pResp) { if (i_pResp) m_pResponse = i_pResp; return NS_OK;};
|
||||
|
||||
NS_IMETHOD GetResponseDataListener(nsIStreamListener* *aListener);
|
||||
|
||||
|
||||
private:
|
||||
nsCOMPtr<nsIURL> m_pURL;
|
||||
PRBool m_bConnected;
|
||||
|
@ -108,6 +111,8 @@ private:
|
|||
nsCOMPtr<nsIHTTPEventSink> m_pEventSink;
|
||||
nsHTTPRequest* m_pRequest;
|
||||
nsHTTPResponse* m_pResponse;
|
||||
|
||||
nsIStreamListener* m_pResponseDataListener;
|
||||
};
|
||||
|
||||
#endif /* _nsHTTPConnection_h_ */
|
||||
|
|
|
@ -55,16 +55,7 @@ nsHTTPResponseListener::OnDataAvailable(nsISupports* context,
|
|||
PRUint32 i_SourceOffset,
|
||||
PRUint32 i_Length)
|
||||
{
|
||||
// we should probably construct the stream only when we get the data...
|
||||
// but for now...
|
||||
nsIStreamListener* syncListener;
|
||||
nsIInputStream* inStr;
|
||||
|
||||
/* Jud... getting some unresolved stuff here... noticed that
|
||||
nsSyncStreamListener isn't being exported!?! */
|
||||
//nsresult rv = NS_NewSyncStreamListener(&syncListener, &inStr);
|
||||
//if (NS_FAILED(rv))
|
||||
// return rv;
|
||||
nsIInputStream* inStr = nsnull;
|
||||
|
||||
// Should I save this as a member variable? yes... todo
|
||||
nsIHTTPEventSink* pSink= nsnull;
|
||||
|
@ -179,8 +170,21 @@ nsHTTPResponseListener::OnDataAvailable(nsISupports* context,
|
|||
|
||||
if (bHeadersDone)
|
||||
{
|
||||
// TODO push extrabuffer up the stream too.. How? JUD?
|
||||
nsresult rv;
|
||||
nsIStreamListener* internalListener = nsnull;
|
||||
|
||||
// Get our end of the pipe between us and the user's GetInputStream()
|
||||
rv = m_pConnection->GetResponseDataListener(&internalListener);
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
// post the data to the stream listener
|
||||
// XXX this is the wrong data and offsets I think.
|
||||
rv = internalListener->OnDataAvailable(context, i_pStream, i_SourceOffset, i_Length);
|
||||
NS_RELEASE(internalListener);
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
}
|
||||
|
||||
// do whatever we want for the event sink
|
||||
return pSink->OnDataAvailable(context, inStr, i_SourceOffset, i_Length);
|
||||
}
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче