[webkit-changes] cvs commit: WebCore/khtml/ecma xmlhttprequest.cpp xmlhttprequest.h

Alexey ap at opensource.apple.com
Fri Dec 23 00:50:14 PST 2005


ap          05/12/23 00:50:14

  Modified:    .        ChangeLog
               khtml/ecma xmlhttprequest.cpp xmlhttprequest.h
  Log:
          Reviewed by Eric Seidel.
  
          - fix http://bugzilla.opendarwin.org/show_bug.cgi?id=3565
            Posting data via XML HTTP Request doesnt work
  
          * khtml/ecma/xmlhttprequest.cpp:
          (KJS::XMLHttpRequest::send): Set application/xml as a default Content-Type;
            use a proper codec for request body if a charset is specified.
          (KJS::XMLHttpRequest::getRequestHeader): Use getSpecificHeader.
          (KJS::XMLHttpRequest::getResponseHeader): Ditto.
          (KJS::XMLHttpRequest::getSpecificHeader): Factored out code from getResponseHeader.
          (KJS::XMLHttpRequestProtoFunc::callAsFunction): Removed a FIXME (this is done in send() now).
          * khtml/ecma/xmlhttprequest.h:
  
  Revision  Changes    Path
  1.33      +2 -0      WebCore/ChangeLog
  
  Index: ChangeLog
  ===================================================================
  RCS file: /cvs/root/WebCore/ChangeLog,v
  retrieving revision 1.32
  retrieving revision 1.33
  diff -u -r1.32 -r1.33
  --- ChangeLog	23 Dec 2005 07:55:25 -0000	1.32
  +++ ChangeLog	23 Dec 2005 08:50:13 -0000	1.33
  @@ -1,3 +1,5 @@
  +2005-12-23  Alexey Proskuryakov  <ap at nypop.com>

        Reviewed by Eric Seidel.

        - fix http://bugzilla.opendarwin.org/show_bug.cgi?id=3565
          Posting data via XML HTTP Request doesnt work

        * khtml/ecma/xmlhttprequest.cpp:
        (KJS::XMLHttpRequest::send): Set application/xml as a default Content-Type;
          use a proper codec for request body if a charset is specified.
        (KJS::XMLHttpRequest::getRequestHeader): Use getSpecificHeader.
        (KJS::XMLHttpRequest::getResponseHeader): Ditto.
        (KJS::XMLHttpRequest::getSpecificHeader): Factored out code from getResponseHeader.
        (KJS::XMLHttpRequestProtoFunc::callAsFunction): Removed a FIXME (this is done in send() now).
        * khtml/ecma/xmlhttprequest.h:
  +
   2005-12-22  Alexey Proskuryakov  <ap at nypop.com>
   
           Reviewed by Darin Adler.
  
  
  
  1.56      +32 -9     WebCore/khtml/ecma/xmlhttprequest.cpp
  
  Index: xmlhttprequest.cpp
  ===================================================================
  RCS file: /cvs/root/WebCore/khtml/ecma/xmlhttprequest.cpp,v
  retrieving revision 1.55
  retrieving revision 1.56
  diff -u -r1.55 -r1.56
  --- xmlhttprequest.cpp	22 Dec 2005 21:10:53 -0000	1.55
  +++ xmlhttprequest.cpp	23 Dec 2005 08:50:13 -0000	1.56
  @@ -1,6 +1,7 @@
   /*
    *  This file is part of the KDE libraries
    *  Copyright (C) 2004 Apple Computer, Inc.
  + *  Copyright (C) 2005 Alexey Proskuryakov <ap at nypop.com>
    *
    *  This library is free software; you can redistribute it and/or
    *  modify it under the terms of the GNU Lesser General Public
  @@ -354,8 +355,21 @@
   
   
     if (method.lower() == "post" && (url.protocol().lower() == "http" || url.protocol().lower() == "https") ) {
  -      // FIXME: determine post encoding correctly by looking in headers for charset
  -      job = KIO::http_post( url, _body.utf8(), false );
  +      QString contentType = getRequestHeader("Content-Type");
  +      QString charset;
  +      if (contentType.isEmpty())
  +        setRequestHeader("Content-Type", "application/xml");
  +      else
  +        charset = getCharset(contentType);
  +      
  +      if (charset.isEmpty())
  +        charset = "UTF-8";
  +      
  +      QTextCodec *codec = QTextCodec::codecForName(charset.latin1());
  +      if (!codec)   // FIXME: report an error?
  +        codec = QTextCodec::codecForName("UTF-8");
  +
  +      job = KIO::http_post(url, codec->fromUnicode(_body), false);
     }
     else
     {
  @@ -428,6 +442,11 @@
     requestHeaders += value;
   }
   
  +QString XMLHttpRequest::getRequestHeader(const QString& name) const
  +{
  +  return getSpecificHeader(requestHeaders, name);
  +}
  +
   JSValue *XMLHttpRequest::getAllResponseHeaders() const
   {
     if (responseHeaders.isEmpty()) {
  @@ -445,27 +464,32 @@
   
   QString XMLHttpRequest::getResponseHeader(const QString& name) const
   {
  -  if (responseHeaders.isEmpty())
  +  return getSpecificHeader(responseHeaders, name);
  +}
  +
  +QString XMLHttpRequest::getSpecificHeader(const QString& headers, const QString& name)
  +{
  +  if (headers.isEmpty())
       return QString();
   
     QRegExp headerLinePattern(name + ":", false);
   
     int matchLength;
  -  int headerLinePos = headerLinePattern.match(responseHeaders, 0, &matchLength);
  +  int headerLinePos = headerLinePattern.match(headers, 0, &matchLength);
     while (headerLinePos != -1) {
  -    if (headerLinePos == 0 || responseHeaders[headerLinePos-1] == '\n') {
  +    if (headerLinePos == 0 || headers[headerLinePos-1] == '\n') {
         break;
       }
       
  -    headerLinePos = headerLinePattern.match(responseHeaders, headerLinePos + 1, &matchLength);
  +    headerLinePos = headerLinePattern.match(headers, headerLinePos + 1, &matchLength);
     }
   
     if (headerLinePos == -1)
       return QString();
       
  -  int endOfLine = responseHeaders.find("\n", headerLinePos + matchLength);
  +  int endOfLine = headers.find("\n", headerLinePos + matchLength);
     
  -  return responseHeaders.mid(headerLinePos + matchLength, endOfLine - (headerLinePos + matchLength)).stripWhiteSpace();
  +  return headers.mid(headerLinePos + matchLength, endOfLine - (headerLinePos + matchLength)).stripWhiteSpace();
   }
   
   bool XMLHttpRequest::responseIsXML() const
  @@ -727,7 +751,6 @@
   	if (args[0]->toObject(exec)->inherits(&DOMDocument::info)) {
   	  DocumentImpl *doc = static_cast<DocumentImpl *>(static_cast<DOMDocument *>(args[0]->toObject(exec))->impl());
             body = doc->toString().qstring();
  -          // FIXME: also need to set content type, including encoding!
   	} else {
   	  // converting certain values (like null) to object can set an exception
   	  exec->clearException();
  
  
  
  1.26      +4 -0      WebCore/khtml/ecma/xmlhttprequest.h
  
  Index: xmlhttprequest.h
  ===================================================================
  RCS file: /cvs/root/WebCore/khtml/ecma/xmlhttprequest.h,v
  retrieving revision 1.25
  retrieving revision 1.26
  diff -u -r1.25 -r1.26
  --- xmlhttprequest.h	20 Dec 2005 08:49:47 -0000	1.25
  +++ xmlhttprequest.h	23 Dec 2005 08:50:13 -0000	1.26
  @@ -2,6 +2,7 @@
   /*
    *  This file is part of the KDE libraries
    *  Copyright (C) 2003 Apple Computer, Inc.
  + *  Copyright (C) 2005 Alexey Proskuryakov <ap at nypop.com>
    *
    *  This library is free software; you can redistribute it and/or
    *  modify it under the terms of the GNU Lesser General Public
  @@ -100,10 +101,13 @@
       void send(const QString& _body);
       void abort();
       void setRequestHeader(const QString& name, const QString &value);
  +    QString getRequestHeader(const QString& name) const;
       JSValue *getAllResponseHeaders() const;
       QString getResponseHeader(const QString& name) const;
       bool responseIsXML() const;
       
  +    static QString getSpecificHeader(const QString& headers, const QString& name);
  +
       void changeState(XMLHttpRequestState newState);
   
       static QPtrDict< QPtrDict<XMLHttpRequest> > &requestsByDocument();
  
  
  



More information about the webkit-changes mailing list