This commit is contained in:
gagan%netscape.com 1999-08-04 15:07:26 +00:00
Родитель aaefb3ff79
Коммит 46143f3127
4 изменённых файлов: 90 добавлений и 19 удалений

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

@ -20,6 +20,7 @@
interface nsIHTTPEventSink; interface nsIHTTPEventSink;
interface nsIStreamListener; interface nsIStreamListener;
interface nsIInputStream;
[scriptable, uuid(35c00430-1938-11d3-933a-000064657374)] [scriptable, uuid(35c00430-1938-11d3-933a-000064657374)]
interface nsIHTTPChannel : nsIChannel interface nsIHTTPChannel : nsIChannel
@ -42,6 +43,12 @@ interface nsIHTTPChannel : nsIChannel
void SetRequestMethod(in unsigned long method); void SetRequestMethod(in unsigned long method);
// NS_IMETHOD SetRequestMethod(HTTPMethod i_Method=HM_GET) = 0; // NS_IMETHOD SetRequestMethod(HTTPMethod i_Method=HM_GET) = 0;
/*
Pass in the post data if any...
*/
void SetPostDataStream(in nsIInputStream postStream);
void GetPostDataStream(out nsIInputStream postStream);
/* /*
Response funtions. A call to any of these implicitly calls Load() on this Response funtions. A call to any of these implicitly calls Load() on this
protocol instance. protocol instance.

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

@ -58,7 +58,8 @@ nsHTTPChannel::nsHTTPChannel(nsIURI* i_URL,
m_pResponseDataListener(nsnull), m_pResponseDataListener(nsnull),
mLoadAttributes(LOAD_NORMAL), mLoadAttributes(LOAD_NORMAL),
mResponseContext(nsnull), mResponseContext(nsnull),
mLoadGroup(nsnull) mLoadGroup(nsnull),
mPostStream(nsnull)
{ {
NS_INIT_REFCNT(); NS_INIT_REFCNT();
@ -76,7 +77,7 @@ nsHTTPChannel::~nsHTTPChannel()
//TODO if we keep our copy of m_URI, then delete it too. //TODO if we keep our copy of m_URI, then delete it too.
NS_IF_RELEASE(m_pRequest); NS_IF_RELEASE(m_pRequest);
NS_IF_RELEASE(m_pResponse); NS_IF_RELEASE(m_pResponse);
NS_IF_RELEASE(mPostStream);
NS_IF_RELEASE(m_pResponseDataListener); NS_IF_RELEASE(m_pResponseDataListener);
NS_IF_RELEASE(mLoadGroup); NS_IF_RELEASE(mLoadGroup);
} }
@ -345,7 +346,8 @@ nsHTTPChannel::GetEventSink(nsIHTTPEventSink* *o_EventSink)
NS_IMETHODIMP NS_IMETHODIMP
nsHTTPChannel::SetRequestMethod(PRUint32/*HTTPMethod*/ i_Method) nsHTTPChannel::SetRequestMethod(PRUint32/*HTTPMethod*/ i_Method)
{ {
return NS_ERROR_NOT_IMPLEMENTED; NS_ASSERTION(m_pRequest, "No request set as yet!");
return m_pRequest ? m_pRequest->SetMethod((HTTPMethod)i_Method) : NS_ERROR_FAILURE;
} }
NS_IMETHODIMP NS_IMETHODIMP
@ -555,4 +557,24 @@ nsHTTPChannel::GetResponseContext(nsISupports** aContext)
return NS_ERROR_NULL_POINTER; return NS_ERROR_NULL_POINTER;
} }
//////////////////////////////////////////////////////////////////////////////// nsresult
nsHTTPChannel::SetPostDataStream(nsIInputStream* postDataStream)
{
NS_IF_RELEASE(mPostStream);
mPostStream = postDataStream;
if (mPostStream)
NS_ADDREF(mPostStream);
return NS_OK;
}
nsresult
nsHTTPChannel::GetPostDataStream(nsIInputStream **o_postStream)
{
if (o_postStream)
{
*o_postStream = mPostStream;
NS_IF_ADDREF(*o_postStream);
return NS_OK;
}
return NS_ERROR_NULL_POINTER;
}

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

@ -84,6 +84,8 @@ public:
NS_IMETHOD GetRequestHeader(const char *headerName, char **_retval); NS_IMETHOD GetRequestHeader(const char *headerName, char **_retval);
NS_IMETHOD SetRequestHeader(const char *headerName, const char *value); NS_IMETHOD SetRequestHeader(const char *headerName, const char *value);
NS_IMETHOD SetRequestMethod(PRUint32 method); NS_IMETHOD SetRequestMethod(PRUint32 method);
NS_IMETHOD SetPostDataStream(nsIInputStream *i_postStream);
NS_IMETHOD GetPostDataStream(nsIInputStream **o_postStream);
NS_IMETHOD GetResponseHeader(const char *headerName, char **_retval); NS_IMETHOD GetResponseHeader(const char *headerName, char **_retval);
NS_IMETHOD GetResponseStatus(PRUint32 *aResponseStatus); NS_IMETHOD GetResponseStatus(PRUint32 *aResponseStatus);
NS_IMETHOD GetResponseString(char * *aResponseString); NS_IMETHOD GetResponseString(char * *aResponseString);
@ -110,6 +112,7 @@ protected:
nsCOMPtr<nsISupports> mResponseContext; nsCOMPtr<nsISupports> mResponseContext;
nsILoadGroup* mLoadGroup; nsILoadGroup* mLoadGroup;
nsIInputStream* mPostStream;
}; };
#endif /* _nsHTTPChannel_h_ */ #endif /* _nsHTTPChannel_h_ */

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

@ -37,7 +37,8 @@
extern PRLogModuleInfo* gHTTPLog; extern PRLogModuleInfo* gHTTPLog;
#endif /* PR_LOGGING */ #endif /* PR_LOGGING */
nsHTTPRequest::nsHTTPRequest(nsIURI* i_pURL, HTTPMethod i_Method, nsIChannel* i_pTransport): nsHTTPRequest::nsHTTPRequest(nsIURI* i_pURL, HTTPMethod i_Method,
nsIChannel* i_pTransport):
m_Method(i_Method), m_Method(i_Method),
m_pArray(new nsVoidArray()), m_pArray(new nsVoidArray()),
m_Version(HTTP_ONE_ZERO), m_Version(HTTP_ONE_ZERO),
@ -145,12 +146,10 @@ nsHTTPRequest::Build()
("\tnsHTTPRequest [this=%x].\tFirst line: %s", ("\tnsHTTPRequest [this=%x].\tFirst line: %s",
this, lineBuffer.GetBuffer())); this, lineBuffer.GetBuffer()));
#if 0
rv = m_Request->Fill(lineBuffer.GetBuffer(), lineBuffer.Length(),
&bytesWritten);
#else
rv = buf->Write(lineBuffer.GetBuffer(), lineBuffer.Length(), rv = buf->Write(lineBuffer.GetBuffer(), lineBuffer.Length(),
&bytesWritten); &bytesWritten);
#ifdef DEBUG_gagan
printf(lineBuffer.GetBuffer());
#endif #endif
if (NS_FAILED(rv)) return rv; if (NS_FAILED(rv)) return rv;
@ -195,25 +194,65 @@ nsHTTPRequest::Build()
("\tnsHTTPRequest [this=%x].\t\t%s\n", ("\tnsHTTPRequest [this=%x].\t\t%s\n",
this, lineBuffer.GetBuffer())); this, lineBuffer.GetBuffer()));
#if 0
rv = m_Request->Fill(lineBuffer.GetBuffer(), lineBuffer.Length(),
&bytesWritten);
#else
rv = buf->Write(lineBuffer.GetBuffer(), lineBuffer.Length(), rv = buf->Write(lineBuffer.GetBuffer(), lineBuffer.Length(),
&bytesWritten); &bytesWritten);
#ifdef DEBUG_gagan
printf(lineBuffer.GetBuffer());
#endif #endif
if (NS_FAILED(rv)) return rv; if (NS_FAILED(rv)) return rv;
lineBuffer.Truncate(); lineBuffer.Truncate();
} }
// Write the final \r\n nsCOMPtr<nsIInputStream> stream;
#if 0 NS_ASSERTION(m_pConnection, "Hee ha!");
rv = m_Request->Fill(CRLF, PL_strlen(CRLF), &bytesWritten); if (NS_FAILED(m_pConnection->GetPostDataStream(getter_AddRefs(stream))))
#else return NS_ERROR_FAILURE;
rv = buf->Write(CRLF, PL_strlen(CRLF), &bytesWritten);
// Currently nsIPostStreamData contains the header info and the data.
// So we are forced to putting this here in the end.
// This needs to change! since its possible for someone to modify it
// TODO- Gagan
if (stream)
{
NS_ASSERTION(m_Method == HM_POST, "Post data without a POST method?");
PRUint32 length;
stream->GetLength(&length);
// TODO Change reading from nsIInputStream to nsIBuffer
char* tempBuff = new char[length+1];
if (!tempBuff)
return NS_ERROR_OUT_OF_MEMORY;
if (NS_FAILED(stream->Read(tempBuff, length, &length)))
{
NS_ASSERTION(0, "Failed to read post data!");
return NS_ERROR_FAILURE;
}
else
{
tempBuff[length] = '\0';
PRUint32 writtenLength;
buf->Write(tempBuff, length, &writtenLength);
#ifdef DEBUG_gagan
printf(tempBuff);
#endif #endif
if (NS_FAILED(rv)) return rv; // ASSERT that you wrote length = stream's length
NS_ASSERTION(writtenLength == length, "Failed to write post data!");
}
delete[] tempBuff;
}
else
{
// Write the final \r\n
rv = buf->Write(CRLF, PL_strlen(CRLF), &bytesWritten);
#ifdef DEBUG_gagan
printf(CRLF);
#endif
if (NS_FAILED(rv)) return rv;
}
PR_LOG(gHTTPLog, PR_LOG_DEBUG, PR_LOG(gHTTPLog, PR_LOG_DEBUG,
("nsHTTPRequest::Build() [this=%x].\tFinished building request.\n", ("nsHTTPRequest::Build() [this=%x].\tFinished building request.\n",