title: Firebase REST API - how to set character encoding?
body: <p>I'm calling the Firebase REST API from a Node.js process. The problem I'm seeing is that POSTS fail when the post body contains non-ASCII characters. This is despite the request returning a "200" status, and the name of a node (which doesn't actually get created).</p>
  
  <p>I'm currently trying something like this:</p>
  
  <pre><code>function push(path, object, callback) {
      console.log("Pushing to "+path+" on: "+firebase.host);
      var fullPath=firebase.basePath+path;
      console.log("fullPath="+fullPath);
      var body = JSON.stringify(object);
      var options = {
          host: firebase.host,
          port: 80,
          method: "POST",
          path: fullPath, //gamma.firebase.com/...
          agent: false,
          headers: {
              'content-type': 'application/json',
              'Content-Length': body.length,
           }
      };
      var req = http.request(options, function(response) {
          var result = "";
          console.dir(response.headers);
          response.on('data', function(chunk) {               
              result+=chunk;
          });
          response.on('end', function() {
              console.error("POST response result: "+result);
              try {
                  callback(JSON.parse(result));
              } catch(e) {
                  callback({ error: e });
              }
          });
          response.on('error', function(e) {
              console.error("POST response error: "+error);
              callback({error: e});
          });
      });
      req.on('error', function(error) {
          console.error("POST request error: "+error);
      });
      req.write(body);
      req.end();
  }
  </code></pre>
  
  <p>The contents of "object" can be as simple as:</p>
  
  <pre><code>{"text": "test\u00a0text"}
  </code></pre>
  
  <p>The result I get back is status 200, and an reasonable-looking child name, which doesn't actually get created.</p>
  
  <p>I've tried setting content-type to a bunch of different things (adding ; charset="UTF-8", for example), and it doesn't seem to affect the results at all. </p>