code: function redirect(options, ctx) {
    // Check if method should be disallowed
    if (options.redirectMethods.indexOf(ctx.method) === -1) {
      ctx.response.status = options.disallowStatus;
      if (options.disallowStatus === 405) {
        ctx.response.set('Allow', options.redirectMethods.join(', '));
      }
      ctx.response.body = '';
      return;
    }
  
    // build redirect url
    const httpsHost = options.hostname || url.parse('http://' + ctx.request.header.host).hostname;
    let redirectTo = `https://${httpsHost}${portToUrlString(options)}`;
  
    if(!options.ignoreUrl) {
      redirectTo += ctx.request.url;
    }
  
    // redirect to secure
    ctx.response.status = options.temporary ? 307 : 301;
    ctx.response.redirect(redirectTo);
  }
docs: middleware itself