Uploaded image for project: 'Moodle'
  1. Moodle
  2. MDL-28439

Portfolio Google Docs export does not work with http 1.0 proxies (Squid)

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Won't Do
    • Icon: Minor Minor
    • None
    • 2.1
    • Portfolio
    • Squid proxy server
    • MOODLE_21_STABLE
    • git@github.com:jason-platts/moodle.git
    • wip-MDL_28439_MASTER
    • Hide

      Set Expect header to empty in the request.

      FIX:

      In lib/googleapi.php (ln 345):

      re-work the google docs send_file function to support request failure in these circumstances.

      Suggested code for review (new bit is the If with comment):
      (note code spacing between brackets and braces is wrong - the rest of the file is like this so I followed)

      <pre>
      /**

      • Sends a file object to google documents
        *
      • @param object $file File object
      • @return boolean True on success
        */
        public function send_file($file){
        $this->google_curl->resetopt();
        $this->google_curl->setHeader("Content-Length: ". $file->get_filesize());
        $this->google_curl->setHeader("Content-Type: ". $file->get_mimetype());
        $this->google_curl->setHeader("Slug: ". $file->get_filename());

      $this->google_curl->post(google_docs::DOCUMENTFEED_URL, $file->get_content());

      if($this->google_curl->info['http_code'] === 201)

      { return true; }

      else if($this->google_curl->info['http_code'] === 417){
      //MDL-? Support http 1.0 proxies.
      $this->google_curl->setHeader("Content-Type: ". $file->get_mimetype());
      $this->google_curl->setHeader('Expect:');
      $this->google_curl->post(google_docs::DOCUMENTFEED_URL, $file->get_content());
      if($this->google_curl->info['http_code'] === 201)

      { return true; }

      else

      { return false; }

      //End MDL-?
      }else

      { return false; }

      }
      </pre>

      Show
      Set Expect header to empty in the request. FIX: In lib/googleapi.php (ln 345): re-work the google docs send_file function to support request failure in these circumstances. Suggested code for review (new bit is the If with comment): (note code spacing between brackets and braces is wrong - the rest of the file is like this so I followed) <pre> /** Sends a file object to google documents * @param object $file File object @return boolean True on success */ public function send_file($file){ $this->google_curl->resetopt(); $this->google_curl->setHeader("Content-Length: ". $file->get_filesize()); $this->google_curl->setHeader("Content-Type: ". $file->get_mimetype()); $this->google_curl->setHeader("Slug: ". $file->get_filename()); $this->google_curl->post(google_docs::DOCUMENTFEED_URL, $file->get_content()); if($this->google_curl->info ['http_code'] === 201) { return true; } else if($this->google_curl->info ['http_code'] === 417){ //MDL-? Support http 1.0 proxies. $this->google_curl->setHeader("Content-Type: ". $file->get_mimetype()); $this->google_curl->setHeader('Expect:'); $this->google_curl->post(google_docs::DOCUMENTFEED_URL, $file->get_content()); if($this->google_curl->info ['http_code'] === 201) { return true; } else { return false; } //End MDL-? }else { return false; } } </pre>
    • Hide
      • Only occurs on sites behind Squid proxy.
        1. Enable 'portfolios' and Google Docs portfolio plugin at site level.
        2. Create a post in any forum.
        3. Make sure it has a fair amount of text in it e.g. 20 lines.
        4. Select Export link and select Google Docs (if choice presented)
        5. Success message should be displayed
      Show
      Only occurs on sites behind Squid proxy. 1. Enable 'portfolios' and Google Docs portfolio plugin at site level. 2. Create a post in any forum. 3. Make sure it has a fair amount of text in it e.g. 20 lines. 4. Select Export link and select Google Docs (if choice presented) 5. Success message should be displayed

      Exporting text from modules using the Portfolio API to Google Docs often fails.

      This seems to be when the content to be exported is more than just a few lines of text.

      Debugging shows an http 417 error being returned from our institutions proxy server (Squid).

      There seems to be issues with a default header (Expect) php curl uses and Squid.

      See:
      http://serverfault.com/questions/107813/why-does-squid-reject-this-multipart-form-data-post-from-curl
      http://www.squid-cache.org/mail-archive/squid-users/201002/0714.html

      Reproduction instructions (only occurs on sites behind Squid proxy):

      1. Enable 'portfolios' and Google Docs portfolio plugin at site level.
      2. Create a post in any forum.
      3. Make sure it has a fair amount of text in it e.g. 20 lines.
      4. Select Export link and select Google Docs (if choice presented)
      5. Instead of getting success message you get:

      Failed to send your data to the selected system: original error was portfolio_gdocs/sendfailed

      Stack trace:
      line 516 of /lib/portfolio/exporter.php: portfolio_export_exception thrown
      line 237 of /lib/portfolio/exporter.php: call to portfolio_exporter->process_stage_send()
      line 243 of /lib/portfolio/exporter.php: call to portfolio_exporter->process_stage()
      line 243 of /lib/portfolio/exporter.php: call to portfolio_exporter->process_stage()
      line 243 of /lib/portfolio/exporter.php: call to portfolio_exporter->process_stage()
      line 243 of /lib/portfolio/exporter.php: call to portfolio_exporter->process_stage()
      line 270 of /portfolio/add.php: call to portfolio_exporter->process_stage()

            poltawski Dan Poltawski
            jp76 Jason Platts
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved:

                Error rendering 'clockify-timesheets-time-tracking-reports:timer-sidebar'. Please contact your Jira administrators.