New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

co-wechat-body

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

co-wechat-body

Wechat xml mesage body parser for koa.

  • 0.1.6
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
36
decreased by-26.53%
Maintainers
1
Weekly downloads
 
Created
Source

co-wechat-body

npm version

Parse wechat xml request body for Koa

Install

NPM

Usage

const koa = require('koa');
const wechatBodyParser = require('co-wechat-body');

const app = koa();
app.use(wechatBodyParser(<options>));

app.use(function *() {
    // the parsed body will store in this.request.body
    // if nothing was parsed, body will be undefined
    this.body = this.request.body;
});

co-wechat-body will carefully check and set this.request.body, so it can intergate well with other body parsers such as koa-bodyparser:

// ...
const bodyParser = require('koa-bodyparser');

// ...
app.use(wechatBodyParser(<options>));
app.use(bodyParser());

Example

http request raw body:

<xml>   
  <return_code><![CDATA[SUCCESS]]></return_code>  
  <return_msg><![CDATA[OK]]></return_msg> 
</xml>

parse result, this.request.body:

{
  "return_code": "SUCCESS",
  "return_msg": "OK"
}

Options

Please refer to (https://www.npmjs.com/package/koa-xml-body#options)

  • encoding: requested encoding. Default is utf8. If not set, the lib will retrive it from content-type(such as content-type:application/xml;charset=gb2312).
  • limit: limit of the body. If the body ends up being larger than this limit, a 413 error code is returned. Default is 1mb.
  • length: length of the body. When content-length is found, it will be overwritten automatically.
  • onerror: error handler. Default is a noop function. It means it will eat the error silently. You can config it to customize the response.
app.use(xmlParser({
    limit: 128,
    length: 200, // '1mb'|1024... If not sure about the effect, just leave it unspecified
    encoding: 'utf8', // lib will detect it from `content-type`
    onerror: (err, ctx) => {
        ctx.throw(err.status, err.message);
    }
}));

Licences

MIT

Keywords

FAQs

Package last updated on 08 Sep 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc