зеркало из https://github.com/mozilla/gecko-dev.git
POSTing works now.
This commit is contained in:
Родитель
aaefb3ff79
Коммит
46143f3127
|
@ -20,6 +20,7 @@
|
|||
|
||||
interface nsIHTTPEventSink;
|
||||
interface nsIStreamListener;
|
||||
interface nsIInputStream;
|
||||
|
||||
[scriptable, uuid(35c00430-1938-11d3-933a-000064657374)]
|
||||
interface nsIHTTPChannel : nsIChannel
|
||||
|
@ -42,6 +43,12 @@ interface nsIHTTPChannel : nsIChannel
|
|||
void SetRequestMethod(in unsigned long method);
|
||||
// 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
|
||||
protocol instance.
|
||||
|
|
|
@ -58,7 +58,8 @@ nsHTTPChannel::nsHTTPChannel(nsIURI* i_URL,
|
|||
m_pResponseDataListener(nsnull),
|
||||
mLoadAttributes(LOAD_NORMAL),
|
||||
mResponseContext(nsnull),
|
||||
mLoadGroup(nsnull)
|
||||
mLoadGroup(nsnull),
|
||||
mPostStream(nsnull)
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
|
||||
|
@ -76,7 +77,7 @@ nsHTTPChannel::~nsHTTPChannel()
|
|||
//TODO if we keep our copy of m_URI, then delete it too.
|
||||
NS_IF_RELEASE(m_pRequest);
|
||||
NS_IF_RELEASE(m_pResponse);
|
||||
|
||||
NS_IF_RELEASE(mPostStream);
|
||||
NS_IF_RELEASE(m_pResponseDataListener);
|
||||
NS_IF_RELEASE(mLoadGroup);
|
||||
}
|
||||
|
@ -345,7 +346,8 @@ nsHTTPChannel::GetEventSink(nsIHTTPEventSink* *o_EventSink)
|
|||
NS_IMETHODIMP
|
||||
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
|
||||
|
@ -555,4 +557,24 @@ nsHTTPChannel::GetResponseContext(nsISupports** aContext)
|
|||
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 SetRequestHeader(const char *headerName, const char *value);
|
||||
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 GetResponseStatus(PRUint32 *aResponseStatus);
|
||||
NS_IMETHOD GetResponseString(char * *aResponseString);
|
||||
|
@ -110,6 +112,7 @@ protected:
|
|||
|
||||
nsCOMPtr<nsISupports> mResponseContext;
|
||||
nsILoadGroup* mLoadGroup;
|
||||
nsIInputStream* mPostStream;
|
||||
};
|
||||
|
||||
#endif /* _nsHTTPChannel_h_ */
|
||||
|
|
|
@ -37,7 +37,8 @@
|
|||
extern PRLogModuleInfo* gHTTPLog;
|
||||
#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_pArray(new nsVoidArray()),
|
||||
m_Version(HTTP_ONE_ZERO),
|
||||
|
@ -145,12 +146,10 @@ nsHTTPRequest::Build()
|
|||
("\tnsHTTPRequest [this=%x].\tFirst line: %s",
|
||||
this, lineBuffer.GetBuffer()));
|
||||
|
||||
#if 0
|
||||
rv = m_Request->Fill(lineBuffer.GetBuffer(), lineBuffer.Length(),
|
||||
&bytesWritten);
|
||||
#else
|
||||
rv = buf->Write(lineBuffer.GetBuffer(), lineBuffer.Length(),
|
||||
&bytesWritten);
|
||||
#ifdef DEBUG_gagan
|
||||
printf(lineBuffer.GetBuffer());
|
||||
#endif
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
|
@ -195,25 +194,65 @@ nsHTTPRequest::Build()
|
|||
("\tnsHTTPRequest [this=%x].\t\t%s\n",
|
||||
this, lineBuffer.GetBuffer()));
|
||||
|
||||
#if 0
|
||||
rv = m_Request->Fill(lineBuffer.GetBuffer(), lineBuffer.Length(),
|
||||
&bytesWritten);
|
||||
#else
|
||||
rv = buf->Write(lineBuffer.GetBuffer(), lineBuffer.Length(),
|
||||
&bytesWritten);
|
||||
#ifdef DEBUG_gagan
|
||||
printf(lineBuffer.GetBuffer());
|
||||
#endif
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
lineBuffer.Truncate();
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIInputStream> stream;
|
||||
NS_ASSERTION(m_pConnection, "Hee ha!");
|
||||
if (NS_FAILED(m_pConnection->GetPostDataStream(getter_AddRefs(stream))))
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
// 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
|
||||
// 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
|
||||
#if 0
|
||||
rv = m_Request->Fill(CRLF, PL_strlen(CRLF), &bytesWritten);
|
||||
#else
|
||||
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,
|
||||
("nsHTTPRequest::Build() [this=%x].\tFinished building request.\n",
|
||||
|
|
Загрузка…
Ссылка в новой задаче