Skip to content

Commit

Permalink
Bug 726434 - Return DOMString for XMLHttpRequest.getAllResponseHeader…
Browse files Browse the repository at this point in the history
…s(); r=bent
  • Loading branch information
Ms2ger committed Feb 21, 2012
1 parent c377301 commit 990ebfa
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 36 deletions.
4 changes: 2 additions & 2 deletions content/base/public/nsIXMLHttpRequest.idl
Original file line number Diff line number Diff line change
Expand Up @@ -183,9 +183,9 @@ interface nsIXMLHttpRequest : nsISupports
* part of a multipart request, not from the original channel.
*
* @returns A string containing all of the response headers.
* NULL if the response has not yet been received.
* The empty string if the response has not yet been received.
*/
string getAllResponseHeaders();
DOMString getAllResponseHeaders();

/**
* Returns the text of the header with the specified name for
Expand Down
49 changes: 21 additions & 28 deletions content/base/src/nsXMLHttpRequest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1317,54 +1317,47 @@ nsXMLHttpRequest::Abort()
return NS_OK;
}

/* string getAllResponseHeaders (); */
/* DOMString getAllResponseHeaders(); */
NS_IMETHODIMP
nsXMLHttpRequest::GetAllResponseHeaders(char **_retval)
nsXMLHttpRequest::GetAllResponseHeaders(nsAString& aResponseHeaders)
{
NS_ENSURE_ARG_POINTER(_retval);
*_retval = nsnull;
aResponseHeaders.Truncate();

// If the state is UNSENT or OPENED,
// return the empty string and terminate these steps.
if (mState & (XML_HTTP_REQUEST_UNSENT |
XML_HTTP_REQUEST_OPENED | XML_HTTP_REQUEST_SENT)) {
*_retval = ToNewCString(EmptyString());
return NS_OK;
}

if (mState & XML_HTTP_REQUEST_USE_XSITE_AC) {
*_retval = ToNewCString(EmptyString());
return NS_OK;
}

nsCOMPtr<nsIHttpChannel> httpChannel = GetCurrentHttpChannel();

if (httpChannel) {
if (nsCOMPtr<nsIHttpChannel> httpChannel = GetCurrentHttpChannel()) {
nsRefPtr<nsHeaderVisitor> visitor = new nsHeaderVisitor();
nsresult rv = httpChannel->VisitResponseHeaders(visitor);
if (NS_SUCCEEDED(rv))
*_retval = ToNewCString(visitor->Headers());
} else if (mChannel) {
// Even non-http channels supply content type.
nsCString value;
if (NS_SUCCEEDED(mChannel->GetContentType(value))) {
nsCString headers;
headers.Append("Content-Type: ");
headers.Append(value);
if (NS_SUCCEEDED(mChannel->GetContentCharset(value)) &&
!value.IsEmpty()) {
headers.Append(";charset=");
headers.Append(value);
}
headers.Append('\n');
*_retval = ToNewCString(headers);
if (NS_SUCCEEDED(httpChannel->VisitResponseHeaders(visitor))) {
aResponseHeaders = NS_ConvertUTF8toUTF16(visitor->Headers());
}
return NS_OK;
}

if (!*_retval) {
*_retval = ToNewCString(EmptyString());
if (!mChannel) {
return NS_OK;
}

// Even non-http channels supply content type.
nsCAutoString value;
if (NS_SUCCEEDED(mChannel->GetContentType(value))) {
aResponseHeaders.AppendLiteral("Content-Type: ");
aResponseHeaders.Append(NS_ConvertUTF8toUTF16(value));
if (NS_SUCCEEDED(mChannel->GetContentCharset(value)) &&
!value.IsEmpty()) {
aResponseHeaders.AppendLiteral(";charset=");
aResponseHeaders.Append(NS_ConvertUTF8toUTF16(value));
}
aResponseHeaders.Append('\n');
}
return NS_OK;
}

Expand Down
12 changes: 6 additions & 6 deletions dom/workers/XMLHttpRequestPrivate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -916,11 +916,11 @@ class AbortRunnable : public WorkerThreadProxySyncRunnable

class GetAllResponseHeadersRunnable : public WorkerThreadProxySyncRunnable
{
nsCString& mResponseHeaders;
nsString& mResponseHeaders;

public:
GetAllResponseHeadersRunnable(WorkerPrivate* aWorkerPrivate, Proxy* aProxy,
nsCString& aResponseHeaders)
nsString& aResponseHeaders)
: WorkerThreadProxySyncRunnable(aWorkerPrivate, aProxy),
mResponseHeaders(aResponseHeaders)
{ }
Expand All @@ -929,7 +929,7 @@ class GetAllResponseHeadersRunnable : public WorkerThreadProxySyncRunnable
MainThreadRun()
{
nsresult rv =
mProxy->mXHR->GetAllResponseHeaders(getter_Copies(mResponseHeaders));
mProxy->mXHR->GetAllResponseHeaders(mResponseHeaders);
return GetDOMExceptionCodeFromResult(rv);
}
};
Expand Down Expand Up @@ -1613,15 +1613,15 @@ XMLHttpRequestPrivate::GetAllResponseHeaders(JSContext* aCx)
return nsnull;
}

nsCString responseHeaders;
nsString responseHeaders;
nsRefPtr<GetAllResponseHeadersRunnable> runnable =
new GetAllResponseHeadersRunnable(mWorkerPrivate, mProxy, responseHeaders);
if (!runnable->Dispatch(aCx)) {
return nsnull;
}

return JS_NewStringCopyN(aCx, responseHeaders.get(),
responseHeaders.Length());
return JS_NewUCStringCopyN(aCx, responseHeaders.get(),
responseHeaders.Length());
}

JSString*
Expand Down

0 comments on commit 990ebfa

Please sign in to comment.