зеркало из https://github.com/mozilla/gecko-dev.git
added header removal functionality and various return value checks
This commit is contained in:
Родитель
e19b816f7e
Коммит
4a6e379644
|
@ -76,7 +76,7 @@ nsHTTPRequest::Build()
|
||||||
if (m_Request)
|
if (m_Request)
|
||||||
NS_ERROR("Request already built!");
|
NS_ERROR("Request already built!");
|
||||||
nsresult rv = NS_NewByteBufferInputStream(&m_Request);
|
nsresult rv = NS_NewByteBufferInputStream(&m_Request);
|
||||||
if (m_Request)
|
if (NS_SUCCEEDED(rv))
|
||||||
{
|
{
|
||||||
|
|
||||||
char lineBuffer[1024]; // verify this length!
|
char lineBuffer[1024]; // verify this length!
|
||||||
|
@ -120,26 +120,26 @@ nsHTTPRequest::Build()
|
||||||
// Write the request method and HTTP version
|
// Write the request method and HTTP version
|
||||||
|
|
||||||
// Add additional headers if any
|
// Add additional headers if any
|
||||||
if (m_pArray && (0< m_pArray->Count()))
|
NS_ASSERTION(m_pArray, "header array is null");
|
||||||
|
|
||||||
|
for (PRInt32 i = m_pArray->Count() - 1; i >= 0; --i)
|
||||||
{
|
{
|
||||||
for (PRInt32 i = m_pArray->Count() - 1; i >= 0; --i)
|
nsHeaderPair* element = NS_STATIC_CAST(nsHeaderPair*, m_pArray[i]);
|
||||||
{
|
//Copy header, put a ": " and then the value + LF
|
||||||
nsHeaderPair* element = NS_STATIC_CAST(nsHeaderPair*, m_pArray->ElementAt(i));
|
// sprintf would be easier... todo change
|
||||||
//Copy header, put a ": " and then the value + LF
|
nsString lineBuffStr;
|
||||||
// sprintf would be easier... todo change
|
element->atom->ToString(lineBuffStr);
|
||||||
nsString lineBuffStr;
|
lineBuffStr.Append(": ");
|
||||||
element->atom->ToString(lineBuffStr);
|
lineBuffStr.Append((const nsString&)*element->value);
|
||||||
lineBuffStr.Append(": ");
|
lineBuffStr.Append(CRLF);
|
||||||
lineBuffStr.Append((const nsString&)*element->value);
|
NS_ASSERTION((lineBuffStr.Length() <= 1024), "Increase line buffer length!");
|
||||||
lineBuffStr.Append(CRLF);
|
lineBuffStr.ToCString(lineBuffer, lineBuffStr.Length());
|
||||||
NS_ASSERTION((lineBuffStr.Length() <= 1024), "Increase line buffer length!");
|
lineBuffer[lineBuffStr.Length()] = '\0';
|
||||||
lineBuffStr.ToCString(lineBuffer, lineBuffStr.Length());
|
rv = m_Request->Fill(lineBuffer, PL_strlen(lineBuffer), &bytesWritten);
|
||||||
lineBuffer[lineBuffStr.Length()] = '\0';
|
if (NS_FAILED(rv)) return rv;
|
||||||
rv = m_Request->Fill(lineBuffer, PL_strlen(lineBuffer), &bytesWritten);
|
lineBuffer[0] = '\0';
|
||||||
if (NS_FAILED(rv)) return rv;
|
|
||||||
lineBuffer[0] = '\0';
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Send the final \n
|
// Send the final \n
|
||||||
lineBuffer[0] = CR;
|
lineBuffer[0] = CR;
|
||||||
lineBuffer[1] = LF;
|
lineBuffer[1] = LF;
|
||||||
|
@ -781,6 +781,7 @@ nsHTTPRequest::GetPriority()
|
||||||
NS_METHOD
|
NS_METHOD
|
||||||
nsHTTPRequest::SetHeader(const char* i_Header, const char* i_Value)
|
nsHTTPRequest::SetHeader(const char* i_Header, const char* i_Value)
|
||||||
{
|
{
|
||||||
|
NS_ASSERTION(m_pArray, "header array doesn't exist.");
|
||||||
if (i_Value)
|
if (i_Value)
|
||||||
{
|
{
|
||||||
//The tempValue gets copied so we can do away with it...
|
//The tempValue gets copied so we can do away with it...
|
||||||
|
@ -794,26 +795,45 @@ nsHTTPRequest::SetHeader(const char* i_Header, const char* i_Value)
|
||||||
else
|
else
|
||||||
return NS_ERROR_OUT_OF_MEMORY;
|
return NS_ERROR_OUT_OF_MEMORY;
|
||||||
}
|
}
|
||||||
else
|
else if (i_Header)
|
||||||
{
|
{
|
||||||
// This should delete any existing headers! TODO
|
nsIAtom* header = NS_NewAtom(i_Header);
|
||||||
return NS_ERROR_NOT_IMPLEMENTED;
|
if (!atom)
|
||||||
|
return NS_ERROR_OUT_OF_MEMORY;
|
||||||
|
|
||||||
|
PRInt32 cnt = m_pArray->Count();
|
||||||
|
for (PRInt32 i = 0; i < cnt; i++) {
|
||||||
|
nsHeaderPair* element = NS_STATIC_CAST(nsHeaderPair*, m_pArray[i]);
|
||||||
|
if (header == element->atom) {
|
||||||
|
m_pArray->RemoveElementAt(i);
|
||||||
|
cnt = m_pArray->Count();
|
||||||
|
i = -1; // reset the counter so we can start from the top again
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
return NS_ERROR_NULL_POINTER;
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_METHOD
|
NS_METHOD
|
||||||
nsHTTPRequest::GetHeader(const char* i_Header, const char* *o_Value) const
|
nsHTTPRequest::GetHeader(const char* i_Header, const char* *o_Value) const
|
||||||
{
|
{
|
||||||
if (m_pArray && (0< m_pArray->Count()))
|
NS_ASSERTION(m_pArray, "header array doesn't exist.");
|
||||||
|
|
||||||
|
if (!i_Header || !o_Value)
|
||||||
|
return NS_ERROR_NULL_POINTER;
|
||||||
|
|
||||||
|
nsIAtom* header = NS_NewAtom(i_Header);
|
||||||
|
if (!header)
|
||||||
|
return NS_ERROR_OUT_OF_MEMORY;
|
||||||
|
|
||||||
|
for (PRInt32 i = m_pArray->Count() - 1; i >= 0; --i)
|
||||||
{
|
{
|
||||||
for (PRInt32 i = m_pArray->Count() - 1; i >= 0; --i)
|
nsHeaderPair* element = NS_STATIC_CAST(nsHeaderPair*, m_pArray[i]);
|
||||||
|
if ((header == element->atom))
|
||||||
{
|
{
|
||||||
nsHeaderPair* element = NS_STATIC_CAST(nsHeaderPair*, m_pArray->ElementAt(i));
|
*o_Value = (element->value) ? element->value->ToNewCString() : nsnull;
|
||||||
if ((element->atom == NS_NewAtom(i_Header)) && o_Value)
|
return NS_OK;
|
||||||
{
|
|
||||||
*o_Value = (element->value) ? element->value->ToNewCString() : nsnull;
|
|
||||||
return NS_OK;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -879,14 +899,17 @@ nsHTTPRequest::OnStopBinding(nsISupports* i_pContext,
|
||||||
// if we could write successfully...
|
// if we could write successfully...
|
||||||
if (NS_SUCCEEDED(iStatus))
|
if (NS_SUCCEEDED(iStatus))
|
||||||
{
|
{
|
||||||
|
nsresult rv;
|
||||||
//Prepare to receive the response!
|
//Prepare to receive the response!
|
||||||
nsHTTPResponseListener* pListener = new nsHTTPResponseListener();
|
nsHTTPResponseListener* pListener = new nsHTTPResponseListener();
|
||||||
m_pTransport->AsyncRead(
|
if (!pListener)
|
||||||
i_pContext,
|
return NS_ERROR_OUT_OF_MEMORY;
|
||||||
m_pConnection->EventQueue(),
|
|
||||||
pListener);
|
rv = m_pTransport->AsyncRead(
|
||||||
//TODO check this portion here...
|
i_pContext,
|
||||||
return pListener ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
|
m_pConnection->EventQueue(),
|
||||||
|
pListener);
|
||||||
|
return rv;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
|
@ -442,7 +442,7 @@ nsHTTPResponse::SetHeader(const char* i_Header, const char* i_Value)
|
||||||
NS_METHOD
|
NS_METHOD
|
||||||
nsHTTPResponse::SetHeaderInternal(const char* i_Header, const char* i_Value)
|
nsHTTPResponse::SetHeaderInternal(const char* i_Header, const char* i_Value)
|
||||||
{
|
{
|
||||||
NS_ASSERTION(m_pArray, "Ooops! array vanished!");
|
NS_ASSERTION(m_pArray, "header array doesn't exist.");
|
||||||
if (i_Value)
|
if (i_Value)
|
||||||
{
|
{
|
||||||
//The tempValue gets copied so we can do away with it...
|
//The tempValue gets copied so we can do away with it...
|
||||||
|
@ -457,30 +457,45 @@ nsHTTPResponse::SetHeaderInternal(const char* i_Header, const char* i_Value)
|
||||||
else
|
else
|
||||||
return NS_ERROR_OUT_OF_MEMORY;
|
return NS_ERROR_OUT_OF_MEMORY;
|
||||||
}
|
}
|
||||||
else
|
else if (i_Header)
|
||||||
{
|
{
|
||||||
// This should delete any existing headers! TODO
|
nsIAtom* header = NS_NewAtom(i_Header);
|
||||||
return NS_ERROR_NOT_IMPLEMENTED;
|
if (!atom)
|
||||||
|
return NS_ERROR_OUT_OF_MEMORY;
|
||||||
|
|
||||||
|
PRInt32 cnt = m_pArray->Count();
|
||||||
|
for (PRInt32 i = 0; i < cnt; i++) {
|
||||||
|
nsHeaderPair* element = NS_STATIC_CAST(nsHeaderPair*, m_pArray[i]);
|
||||||
|
if (header == element->atom) {
|
||||||
|
m_pArray->RemoveElementAt(i);
|
||||||
|
cnt = m_pArray->Count();
|
||||||
|
i = -1; // reset the counter so we can start from the top again
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
return NS_ERROR_NULL_POINTER;
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_METHOD
|
NS_METHOD
|
||||||
nsHTTPResponse::GetHeader(const char* i_Header, const char* *o_Value) const
|
nsHTTPResponse::GetHeader(const char* i_Header, const char* *o_Value) const
|
||||||
{
|
{
|
||||||
// TODO
|
NS_ASSERTION(m_pArray, "header array doesn't exist.");
|
||||||
// Common out the headerpair array functionality from
|
|
||||||
// request and put it in a class
|
if (!i_Header || !o_Value)
|
||||||
nsIAtom* iAtom = NS_NewAtom(i_Header);
|
return NS_ERROR_NULL_POINTER;
|
||||||
if (m_pArray && (0< m_pArray->Count()))
|
|
||||||
|
nsIAtom* header = NS_NewAtom(i_Header);
|
||||||
|
if (!header)
|
||||||
|
return NS_ERROR_OUT_OF_MEMORY;
|
||||||
|
|
||||||
|
for (PRInt32 i = m_pArray->Count() - 1; i >= 0; --i)
|
||||||
{
|
{
|
||||||
for (PRInt32 i = m_pArray->Count() - 1; i >= 0; --i)
|
nsHeaderPair* element = NS_STATIC_CAST(nsHeaderPair*, m_pArray[i]);
|
||||||
|
if ((header == element->atom))
|
||||||
{
|
{
|
||||||
nsHeaderPair* element = NS_STATIC_CAST(nsHeaderPair*, m_pArray->ElementAt(i));
|
*o_Value = (element->value) ? element->value->ToNewCString() : nsnull;
|
||||||
if ((element->atom == iAtom) && o_Value)
|
return NS_OK;
|
||||||
{
|
|
||||||
*o_Value = (element->value) ? element->value->ToNewCString() : nsnull;
|
|
||||||
return NS_OK;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Загрузка…
Ссылка в новой задаче