Transitioning from nsIHttpEventSink.h to nsIHTTPEventSink.idl Also cleaned up the event sink to only have OnHeadersAvailable and OnRedirect as messages.

Fixed bug 24329-- proxy auths. We were not using the new call to setOverrideRequestSpec.
Part fix for bug 27048, HTTP now uses nsIHTTPEventSink and uses nsIPrompt for authentication.
r=valeski,a=jar
This commit is contained in:
gagan%netscape.com 2000-03-08 00:31:49 +00:00
Родитель 0515578bb7
Коммит faf228f2f5
6 изменённых файлов: 87 добавлений и 75 удалений

Просмотреть файл

@ -26,7 +26,7 @@
#include "prlong.h"
#include "nsHTTPChannel.h"
#include "netCore.h"
#include "nsIHttpEventSink.h"
#include "nsIHTTPEventSink.h"
#include "nsIHTTPProtocolHandler.h"
#include "nsHTTPRequest.h"
#include "nsHTTPResponse.h"
@ -52,10 +52,7 @@
#include "nsIScriptSecurityManager.h"
#include "nsIProxy.h"
#include "nsMimeTypes.h"
#ifdef DEBUG_gagan
#include "nsUnixColorPrintf.h"
#endif
#include "nsIPrompt.h"
// FIXME - Temporary include. Delete this when cache is enabled on all platforms
#include "nsIPref.h"
@ -139,6 +136,7 @@ nsHTTPChannel::~nsHTTPChannel()
mHandler = null_nsCOMPtr();
mEventSink = null_nsCOMPtr();
mPrompter = null_nsCOMPtr();
mResponseContext = null_nsCOMPtr();
mLoadGroup = null_nsCOMPtr();
CRTFREEIF(mProxy);
@ -430,7 +428,8 @@ nsHTTPChannel::GetNotificationCallbacks(nsIInterfaceRequestor* *aNotificationCal
}
NS_IMETHODIMP
nsHTTPChannel::SetNotificationCallbacks(nsIInterfaceRequestor* aNotificationCallbacks)
nsHTTPChannel::SetNotificationCallbacks(nsIInterfaceRequestor*
aNotificationCallbacks)
{
nsresult rv = NS_OK;
mCallbacks = aNotificationCallbacks;
@ -442,6 +441,9 @@ nsHTTPChannel::SetNotificationCallbacks(nsIInterfaceRequestor* aNotificationCall
(void)mCallbacks->GetInterface(NS_GET_IID(nsIHTTPEventSink),
getter_AddRefs(mEventSink));
(void)mCallbacks->GetInterface(NS_GET_IID(nsIPrompt),
getter_AddRefs(mPrompter));
(void)mCallbacks->GetInterface(NS_GET_IID(nsIProgressEventSink),
getter_AddRefs(mProgressEventSink));
}
@ -798,7 +800,8 @@ nsHTTPChannel::CheckCache()
if (!mCachedResponse)
return NS_ERROR_OUT_OF_MEMORY;
NS_ADDREF(mCachedResponse);
nsSubsumeCStr cachedHeadersCStr(NS_CONST_CAST(char*, NS_STATIC_CAST(const char*, cachedHeaders)),
nsSubsumeCStr cachedHeadersCStr(NS_CONST_CAST(char*,
NS_STATIC_CAST(const char*, cachedHeaders)),
PR_FALSE);
rv = mCachedResponse->ParseHeaders(cachedHeadersCStr);
if (NS_FAILED(rv)) return rv;
@ -883,7 +886,6 @@ nsHTTPChannel::CheckCache()
return NS_OK;
}
// If the data in the cache hasn't expired, then there's no need to
// talk with the server, not even to do an if-modified-since. This
// method creates a stream from the cache, synthesizing all the various
@ -1183,7 +1185,44 @@ nsHTTPChannel::Open(void)
mRequest->SetTransport(transport);
rv = mRequest->WriteRequest((mProxy && *mProxy));
// if using proxy...
nsXPIDLCString requestSpec;
rv = mRequest->GetOverrideRequestSpec(getter_Copies(requestSpec));
// no one has overwritten this value as yet...
if (!requestSpec && mProxy && *mProxy)
{
nsXPIDLCString strurl;
if(NS_SUCCEEDED(mURI->GetSpec(getter_Copies(strurl))))
mRequest->SetOverrideRequestSpec(strurl);
}
// Check to see if an authentication header is required
nsAuthEngine* pAuthEngine = nsnull;
if (NS_SUCCEEDED(mHandler->GetAuthEngine(&pAuthEngine)) && pAuthEngine)
{
nsXPIDLCString authStr;
if (NS_SUCCEEDED(pAuthEngine->GetAuthString(mURI,
getter_Copies(authStr))))
{
if (authStr && *authStr)
rv = mRequest->SetHeader(nsHTTPAtoms::Authorization, authStr);
}
if (mProxy && *mProxy)
{
nsXPIDLCString proxyAuthStr;
if (NS_SUCCEEDED(pAuthEngine->GetProxyAuthString(mProxy,
mProxyPort,
getter_Copies(proxyAuthStr))))
{
if (proxyAuthStr && *proxyAuthStr)
rv = mRequest->SetHeader(nsHTTPAtoms::Proxy_Authorization,
proxyAuthStr);
}
}
}
rv = mRequest->WriteRequest();
if (NS_FAILED(rv)) return rv;
mState = HS_WAITING_FOR_RESPONSE;
@ -1485,6 +1524,7 @@ nsHTTPChannel::Authenticate(const char *iChallenge, PRBool iProxyAuth)
This is dependent on the completion of the new
design of the webshell.
*/
#if 0
nsCOMPtr<nsIAppShellService> appShellService(do_GetService(kAppShellServiceCID));
NS_ENSURE_TRUE(appShellService, NS_ERROR_FAILURE);
@ -1501,9 +1541,12 @@ nsHTTPChannel::Authenticate(const char *iChallenge, PRBool iProxyAuth)
NS_GET_IID(nsINetPrompt),
prompter, PROXY_SYNC,
(void**)&proxyprompter);
#endif
if (!mPrompter)
return rv;
PRUnichar *user=nsnull, *passwd=nsnull;
PRBool retval;
PRBool retval = PR_FALSE;
//TODO localize it!
nsAutoString message = "Enter username for ";
@ -1514,6 +1557,7 @@ nsHTTPChannel::Authenticate(const char *iChallenge, PRBool iProxyAuth)
nsXPIDLCString urlCString;
mURI->GetHost(getter_Copies(urlCString));
/*
rv = proxyprompter->PromptUsernameAndPassword(urlCString,
PR_TRUE,
NULL,
@ -1524,8 +1568,14 @@ nsHTTPChannel::Authenticate(const char *iChallenge, PRBool iProxyAuth)
// Must be done as not managed for you.
proxyprompter->Release();
*/
rv = mPrompter->PromptUsernameAndPassword(
message.GetUnicode(),
&user,
&passwd,
&retval);
if (retval)
if (NS_SUCCEEDED(rv) && (retval))
{
nsAutoString temp(user);
if (passwd) {
@ -1956,19 +2006,7 @@ nsHTTPChannel::SetReferrer(nsIURI *referrer, PRUint32 referrerLevel)
{
if ((referrerLevel == nsIHTTPChannel::REFERRER_NON_HTTP) ||
(0 == PL_strncasecmp((const char*)spec, "http",4)))
#ifdef DEBUG_gagan
{
PRINTF_CYAN;
nsXPIDLCString thisURL;
mURI->GetSpec(getter_Copies(thisURL));
printf("For: %s\nUsing Referrer: %s\n",
(const char*)thisURL,
(const char*)spec);
#endif
return SetRequestHeader(nsHTTPAtoms::Referer, spec);
#ifdef DEBUG_gagan
}
#endif
}
return NS_OK;
}

Просмотреть файл

@ -31,7 +31,6 @@
#include "nsIEventQueue.h"
#include "nsIInterfaceRequestor.h"
#include "nsIProgressEventSink.h"
#include "nsIHttpEventSink.h"
#include "nsILoadGroup.h"
#include "nsCOMPtr.h"
#include "nsString.h"
@ -41,6 +40,7 @@
#include "nsIStreamObserver.h"
#include "nsICachedNetData.h"
#include "nsIProxy.h"
#include "nsIPrompt.h"
class nsHTTPRequest;
class nsHTTPResponse;
@ -135,6 +135,7 @@ protected:
HTTPState mState;
nsCString mVerb;
nsCOMPtr<nsIHTTPEventSink> mEventSink;
nsCOMPtr<nsIPrompt> mPrompter;
nsCOMPtr<nsIProgressEventSink> mProgressEventSink;
nsCOMPtr<nsIInterfaceRequestor> mCallbacks;

Просмотреть файл

@ -33,7 +33,7 @@
#include "nsISocketTransportService.h"
#include "nsIServiceManager.h"
#include "nsIInterfaceRequestor.h"
#include "nsIHttpEventSink.h"
#include "nsIHTTPEventSink.h"
#include "nsIFileStreams.h"
#include "nsIStringStream.h"
#include "nsHTTPEncodeStream.h"
@ -42,9 +42,6 @@
#include "nsIPref.h"
#include "nsIProtocolProxyService.h"
#ifdef DEBUG_gagan
#include "nsUnixColorPrintf.h"
#endif
#include "nsILocalFile.h"
#include "nsNetUtil.h"
#include "nsICategoryManager.h"
@ -791,19 +788,10 @@ nsresult nsHTTPHandler::RequestTransport(nsIURI* i_Uri,
if (idleport == -1)
GetDefaultPort(&idleport);
#ifdef DEBUG_gagan
printf(STARTYELLOW "%s:%d\n",
(const char*)idlehost, idleport);
#endif
if (idleport == port)
{
// Addref it before removing it!
NS_ADDREF(trans);
#ifdef DEBUG_gagan
PRINTF_BLUE;
printf("Found a match in idle list!\n");
#endif
// Remove it from the idle
mIdleTransports->RemoveElement(trans);
//break;// break out of the for loop
@ -1063,10 +1051,6 @@ nsHTTPHandler::PrefsChanged(const char* pref)
rv = mPrefs->GetIntPref("network.sendRefererHeader",&referrerLevel);
if (NS_SUCCEEDED(rv) && referrerLevel>0)
mReferrerLevel = referrerLevel;
#ifdef DEBUG_gagan
PRINTF_CYAN;
printf("network.sendRefererHeader = %d\n", mReferrerLevel);
#endif
}
// Things read only during initialization...

Просмотреть файл

@ -111,23 +111,6 @@ nsHTTPRequest::nsHTTPRequest(nsIURI* i_URL, HTTPMethod i_Method):
//SetHeader(nsHTTPAtoms::Accept, "image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, image/png, */*");
SetHeader(nsHTTPAtoms::Accept, "*/*");
// Check to see if an authentication header is required
nsAuthEngine* pAuthEngine = nsnull;
rv = httpHandler->GetAuthEngine(&pAuthEngine);
if (NS_SUCCEEDED(rv) && pAuthEngine)
{
// Qvq lbh xabj gung t?? Ebg13f n yvar va IVZ? Jbj.
nsXPIDLCString authStr;
//PRUint32 authType = 0;
if (NS_SUCCEEDED(pAuthEngine->GetAuthString(mURI,
getter_Copies(authStr))))
//&authType)) && (authType == 1))
{
if (authStr && *authStr)
SetHeader(nsHTTPAtoms::Authorization, authStr);
}
}
nsXPIDLCString acceptLanguages;
// Add the Accept-Language header
rv = httpHandler->GetAcceptLanguages(
@ -232,7 +215,7 @@ nsHTTPRequest::Resume(void)
// Finally our own methods...
nsresult nsHTTPRequest::WriteRequest(PRBool aIsProxied)
nsresult nsHTTPRequest::WriteRequest()
{
nsresult rv;
if (!mURI) {
@ -282,8 +265,17 @@ nsresult nsHTTPRequest::WriteRequest(PRBool aIsProxied)
//
mRequestBuffer.Append(MethodToString(mMethod));
if (mRequestSpec)
// Request spec gets set for proxied cases-
if (!mRequestSpec)
{
rv = mURI->GetPath(getter_Copies(autoBuffer));
mRequestBuffer.Append(autoBuffer);
}
else
mRequestBuffer.Append(mRequestSpec);
//if (mRequestSpec)
/*
else
{
if (aIsProxied) {
@ -293,6 +285,7 @@ nsresult nsHTTPRequest::WriteRequest(PRBool aIsProxied)
}
mRequestBuffer.Append(autoBuffer);
}
*/
//Trim off the # portion if any...
int refLocation = mRequestBuffer.RFind("#");

Просмотреть файл

@ -108,7 +108,7 @@ public:
nsresult ReleaseTransport(nsIChannel *aTransport);
// Build the actual request string based on the settings.
nsresult WriteRequest(PRBool aIsProxied = PR_FALSE);
nsresult WriteRequest();
nsresult GetPostDataStream(nsIInputStream* *aResult);
nsresult SetPostDataStream(nsIInputStream* aStream);

Просмотреть файл

@ -28,7 +28,6 @@
#include "nsIBufferInputStream.h"
#include "nsHTTPChannel.h"
#include "nsHTTPResponse.h"
#include "nsIHttpEventSink.h"
#include "nsCRT.h"
#include "nsHTTPAtoms.h"
@ -82,8 +81,6 @@ nsHTTPResponseListener::nsHTTPResponseListener(nsHTTPChannel *aChannel)
("Creating nsHTTPResponseListener [this=%x] for URI: %s.\n",
this, (const char *)urlCString));
#endif
}
nsHTTPResponseListener::~nsHTTPResponseListener()
@ -341,8 +338,9 @@ nsHTTPServerListener::OnDataAvailable(nsIChannel* channel,
("\tOnDataAvailable [this=%x]. Calling consumer "
"OnDataAvailable.\tlength:%d\n", this, i_Length));
rv = mResponseDataListener->OnDataAvailable(mChannel, mChannel->mResponseContext,
i_pStream, 0, i_Length);
rv = mResponseDataListener->OnDataAvailable(mChannel,
mChannel->mResponseContext,
i_pStream, 0, i_Length);
if (NS_FAILED(rv)) {
PR_LOG(gHTTPLog, PR_LOG_ERROR,
("\tOnDataAvailable [this=%x]. Consumer failed!"
@ -442,7 +440,8 @@ nsresult nsHTTPServerListener::Abort()
}
nsresult nsHTTPServerListener::FireSingleOnData(nsIStreamListener *aListener, nsISupports *aContext)
nsresult nsHTTPServerListener::FireSingleOnData(nsIStreamListener *aListener,
nsISupports *aContext)
{
nsresult rv;
@ -451,8 +450,9 @@ nsresult nsHTTPServerListener::FireSingleOnData(nsIStreamListener *aListener, ns
if (NS_FAILED(rv)) return rv;
if (mBytesReceived && mResponseDataListener) {
rv = mResponseDataListener->OnDataAvailable(mChannel, mChannel->mResponseContext,
mDataStream, 0, mBytesReceived);
rv = mResponseDataListener->OnDataAvailable(mChannel,
mChannel->mResponseContext,
mDataStream, 0, mBytesReceived);
}
mDataStream = 0;
}
@ -561,8 +561,6 @@ nsresult nsHTTPServerListener::ParseStatusLine(nsIBufferInputStream* in,
return rv;
}
nsresult nsHTTPServerListener::ParseHTTPHeader(nsIBufferInputStream* in,
PRUint32 aLength,
PRUint32 *aBytesRead)
@ -608,7 +606,8 @@ nsresult nsHTTPServerListener::ParseHTTPHeader(nsIBufferInputStream* in,
if (NS_FAILED(rv)) return rv;
if (bFoundString && offsetOfEnd >= aLength) bFoundString = PR_FALSE;
NS_ASSERTION(!(!bFoundString && offsetOfEnd == 0), "should have been checked above");
NS_ASSERTION(!(!bFoundString && offsetOfEnd == 0),
"should have been checked above");
if (!bFoundString || offsetOfEnd != 0) {
break; // neither space nor tab, so jump out of the loop
}
@ -687,6 +686,3 @@ nsresult nsHTTPServerListener::FinishedResponseHeaders(void)
return rv;
}