title: Scraping using google cloud function it finished with status code: 304
body: <p>I am trying out google cloud functions, it works but finishes with status code of 304 not sure what is the reason.
  Below is the code,</p>
  
  <pre><code>//gcloud beta functions deploy scrapeGitCollection --trigger-http
  var cheerio = require('cheerio');
  var request = require('request');
  
  function getDateTime() {
  
      var date = new Date();
  
      var hour = date.getHours();
      hour = (hour &lt; 10 ? "0" : "") + hour;
  
      var min  = date.getMinutes();
      min = (min &lt; 10 ? "0" : "") + min;
  
      var sec  = date.getSeconds();
      sec = (sec &lt; 10 ? "0" : "") + sec;
  
      var year = date.getFullYear();
  
      var month = date.getMonth() + 1;
      month = (month &lt; 10 ? "0" : "") + month;
  
      var day  = date.getDate();
      day = (day &lt; 10 ? "0" : "") + day;
  
      return year + "/" + month + "/" + day + " " + hour + ":" + min + ":" + sec;
  
    }  
  
  var scrape = new Promise((resolve, reject) =&gt;{
      var text;
      var array = [];
  
      request({
          method: 'GET',
          url: 'https://github.com/collections'
      }, function(err, response, body) {
          if (err) return reject(err);
  
          // Tell Cherrio to load the HTML
          $ = cheerio.load(body);
          $('.col-10 h2 a').each(function(i, element) {
              var node = $(this);
              text = node.text();
              //console.log(text);
              array.push(text);
          });
  
          text = JSON.stringify(array);
          console.log(text);
          resolve(text);
      });     
  });
  
  // [START functions_helloworld_http]
  /**
   * HTTP Cloud Function.
   * @param {Object} req Cloud Function request context.
   * @param {Object} res Cloud Function response context.
   *
  */
  exports.scrapeGitCollection = (req, res) =&gt; {
      console.log('Triggered @ '+getDateTime());
      scrape.then((data) =&gt;{
          res.send(`Hello ${data || 'World'}!`);
      }).catch( (errorMessage) =&gt;{
          console.error(errorMessage);
      });
  
    };
  // [END functions_helloworld_http]
  </code></pre>
  
  <p>This is the log i see in stackdriver</p>
  
  <pre><code>2018-07-05 22:19:39.181 IST
  scrapeGitCollection
  x6mbdi17rdj7
  Function execution took 7 ms, finished with status code: 304
  {
   insertId:  "000000-4f8925ba-a5a5-4f0e-9c32-906e91374e32"  
   labels: {…}  
   logName:  "projects/btd-in-16062018/logs/cloudfunctions.googleapis.com%2Fcloud-functions"  
   receiveTimestamp:  "2018-07-05T16:49:45.425756526Z"  
   resource: {…}  
   severity:  "DEBUG"  
   textPayload:  "Function execution took 7 ms, finished with status code: 304"  
   timestamp:  "2018-07-05T16:49:39.181731257Z"  
  }
  </code></pre>
  
  <p>For debugging purposes, i had added below line in scrape() function, it did not appear in the log.</p>
  
  <pre><code>console.log(text);
  </code></pre>
  
  <p>If i forcibly say as below, i get the above console.log text with the results. </p>
  
  <pre><code>res.status(200).send(`Hello ${data || 'World'}!`);
  </code></pre>
  
  <p>I don't want to forcibly say status(200). Would like to resolve 304 which i was getting earlier.</p>