333
schangxiang@126.com
2025-09-19 18966e02fb573c7e2bb0c6426ed792b38b910940
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
'use strict';
 
const jsonpBody = require('jsonp-body');
const { JSONP_CONFIG } = require('../../lib/private_key');
 
module.exports = {
  /**
   * detect if response should be jsonp
   */
  get acceptJSONP() {
    return !!(this[JSONP_CONFIG] && this[JSONP_CONFIG].jsonpFunction);
  },
 
  /**
   * JSONP wrap body function
   * Set jsonp response wrap function, other plugin can use it.
   * If not necessary, please don't use this method in your application code.
   * @param {Object} body respones body
   * @private
   */
  createJsonpBody(body) {
    const jsonpConfig = this[JSONP_CONFIG];
    if (!jsonpConfig || !jsonpConfig.jsonpFunction) {
      this.body = body;
      return;
    }
 
    this.set('x-content-type-options', 'nosniff');
    this.type = 'js';
    body = body === undefined ? null : body;
    // protect from jsonp xss
    this.body = jsonpBody(body, jsonpConfig.jsonpFunction, jsonpConfig.options);
  },
};