Get hands-on experience with 20+ free Google Cloud products and $300 in free credit for new customers.

Edgemicro intro plugin appending to response body instead of replacing

Not applicable

I'm working through the first custom plugin tutorial for edgemicro found here: http://docs.apigee.com/microgateway/latest/develop-plugins. I've run into some peculiar behavior though.

Here is my plugin code:

'use strict';
  
var debug = require('debug')('plugin:response-override');


module.exports.init = function(config, logger, stats) {


  return {
   
    ondata_response: function(req, res, data, next) {
      debug('***** plugin ondata_response');
      next(null, null);
    },
    
    onend_response: function(req, res, data, next) {
      debug('***** plugin onend_response');
      next(null, "Hello, World!\n\n");
    }
  };
}

Instead of replacing the response body with custom text. My plugin simply appends the text to the current response body.

HTTP/1.1 200 OK
content-type: application/json; charset=utf-8
date: Mon, 10 Oct 2016 14:31:11 GMT
etag: W/"1cd-igZDs61JMAiJo6ZDx/UFDQ"
x-powered-by: Apigee
x-response-time: 635
Connection: keep-alive
Transfer-Encoding: chunked

{"headers":{"host":"mocktarget.apigee.net","accept":"*/*","user-agent":"curl/7.43.0","via":"undefined1.1 localhost","x-authorization-claims":"eyJzY29wZXMiOltdfQ==","x-forwarded-host":"undefinedlocalhost:8000","x-request-id":"d68c00d0-8ef5-11e6-8c68-5758f301a7dc.30bc13b0-8ef6-11e6-8c68-5758f301a7dc","x-forwarded-for":"undefined::1, 68.49.164.231","x-forwarded-port":"80","x-forwarded-proto":"http","connection":"keep-alive"},"method":"GET","url":"/","body":""}Hello, World!

Any ideas on what my issue is?

0 0 176
0 REPLIES 0