Skip to content
Snippets Groups Projects
index.js 6.29 MiB
Newer Older
  • Learn to ignore specific revisions
  • 14001 14002 14003 14004 14005 14006 14007 14008 14009 14010 14011 14012 14013 14014 14015 14016 14017 14018 14019 14020 14021 14022 14023 14024 14025 14026 14027 14028 14029 14030 14031 14032 14033 14034 14035 14036 14037 14038 14039 14040 14041 14042 14043 14044 14045 14046 14047 14048 14049 14050 14051 14052 14053 14054 14055 14056 14057 14058 14059 14060 14061 14062 14063 14064 14065 14066 14067 14068 14069 14070 14071 14072 14073 14074 14075 14076 14077 14078 14079 14080 14081 14082 14083 14084 14085 14086 14087 14088 14089 14090 14091 14092 14093 14094 14095 14096 14097 14098 14099 14100 14101 14102 14103 14104 14105 14106 14107 14108 14109 14110 14111 14112 14113 14114 14115 14116 14117 14118 14119 14120 14121 14122 14123 14124 14125 14126 14127 14128 14129 14130 14131 14132 14133 14134 14135 14136 14137 14138 14139 14140 14141 14142 14143 14144 14145 14146 14147 14148 14149 14150 14151 14152 14153 14154 14155 14156 14157 14158 14159 14160 14161 14162 14163 14164 14165 14166 14167 14168 14169 14170 14171 14172 14173 14174 14175 14176 14177 14178 14179 14180 14181 14182 14183 14184 14185 14186 14187 14188 14189 14190 14191 14192 14193 14194 14195 14196 14197 14198 14199 14200 14201 14202 14203 14204 14205 14206 14207 14208 14209 14210 14211 14212 14213 14214 14215 14216 14217 14218 14219 14220 14221 14222 14223 14224 14225 14226 14227 14228 14229 14230 14231 14232 14233 14234 14235 14236 14237 14238 14239 14240 14241 14242 14243 14244 14245 14246 14247 14248 14249 14250 14251 14252 14253 14254 14255 14256 14257 14258 14259 14260 14261 14262 14263 14264 14265 14266 14267 14268 14269 14270 14271 14272 14273 14274 14275 14276 14277 14278 14279 14280 14281 14282 14283 14284 14285 14286 14287 14288 14289 14290 14291 14292 14293 14294 14295 14296 14297 14298 14299 14300 14301 14302 14303 14304 14305 14306 14307 14308 14309 14310 14311 14312 14313 14314 14315 14316 14317 14318 14319 14320 14321 14322 14323 14324 14325 14326 14327 14328 14329 14330 14331 14332 14333 14334 14335 14336 14337 14338 14339 14340 14341 14342 14343 14344 14345 14346 14347 14348 14349 14350 14351 14352 14353 14354 14355 14356 14357 14358 14359 14360 14361 14362 14363 14364 14365 14366 14367 14368 14369 14370 14371 14372 14373 14374 14375 14376 14377 14378 14379 14380 14381 14382 14383 14384 14385 14386 14387 14388 14389 14390 14391 14392 14393 14394 14395 14396 14397 14398 14399 14400 14401 14402 14403 14404 14405 14406 14407 14408 14409 14410 14411 14412 14413 14414 14415 14416 14417 14418 14419 14420 14421 14422 14423 14424 14425 14426 14427 14428 14429 14430 14431 14432 14433 14434 14435 14436 14437 14438 14439 14440 14441 14442 14443 14444 14445 14446 14447 14448 14449 14450 14451 14452 14453 14454 14455 14456 14457 14458 14459 14460 14461 14462 14463 14464 14465 14466 14467 14468 14469 14470 14471 14472 14473 14474 14475 14476 14477 14478 14479 14480 14481 14482 14483 14484 14485 14486 14487 14488 14489 14490 14491 14492 14493 14494 14495 14496 14497 14498 14499 14500 14501 14502 14503 14504 14505 14506 14507 14508 14509 14510 14511 14512 14513 14514 14515 14516 14517 14518 14519 14520 14521 14522 14523 14524 14525 14526 14527 14528 14529 14530 14531 14532 14533 14534 14535 14536 14537 14538 14539 14540 14541 14542 14543 14544 14545 14546 14547 14548 14549 14550 14551 14552 14553 14554 14555 14556 14557 14558 14559 14560 14561 14562 14563 14564 14565 14566 14567 14568 14569 14570 14571 14572 14573 14574 14575 14576 14577 14578 14579 14580 14581 14582 14583 14584 14585 14586 14587 14588 14589 14590 14591 14592 14593 14594 14595 14596 14597 14598 14599 14600 14601 14602 14603 14604 14605 14606 14607 14608 14609 14610 14611 14612 14613 14614 14615 14616 14617 14618 14619 14620 14621 14622 14623 14624 14625 14626 14627 14628 14629 14630 14631 14632 14633 14634 14635 14636 14637 14638 14639 14640 14641 14642 14643 14644 14645 14646 14647 14648 14649 14650 14651 14652 14653 14654 14655 14656 14657 14658 14659 14660 14661 14662 14663 14664 14665 14666 14667 14668 14669 14670 14671 14672 14673 14674 14675 14676 14677 14678 14679 14680 14681 14682 14683 14684 14685 14686 14687 14688 14689 14690 14691 14692 14693 14694 14695 14696 14697 14698 14699 14700 14701 14702 14703 14704 14705 14706 14707 14708 14709 14710 14711 14712 14713 14714 14715 14716 14717 14718 14719 14720 14721 14722 14723 14724 14725 14726 14727 14728 14729 14730 14731 14732 14733 14734 14735 14736 14737 14738 14739 14740 14741 14742 14743 14744 14745 14746 14747 14748 14749 14750 14751 14752 14753 14754 14755 14756 14757 14758 14759 14760 14761 14762 14763 14764 14765 14766 14767 14768 14769 14770 14771 14772 14773 14774 14775 14776 14777 14778 14779 14780 14781 14782 14783 14784 14785 14786 14787 14788 14789 14790 14791 14792 14793 14794 14795 14796 14797 14798 14799 14800 14801 14802 14803 14804 14805 14806 14807 14808 14809 14810 14811 14812 14813 14814 14815 14816 14817 14818 14819 14820 14821 14822 14823 14824 14825 14826 14827 14828 14829 14830 14831 14832 14833 14834 14835 14836 14837 14838 14839 14840 14841 14842 14843 14844 14845 14846 14847 14848 14849 14850 14851 14852 14853 14854 14855 14856 14857 14858 14859 14860 14861 14862 14863 14864 14865 14866 14867 14868 14869 14870 14871 14872 14873 14874 14875 14876 14877 14878 14879 14880 14881 14882 14883 14884 14885 14886 14887 14888 14889 14890 14891 14892 14893 14894 14895 14896 14897 14898 14899 14900 14901 14902 14903 14904 14905 14906 14907 14908 14909 14910 14911 14912 14913 14914 14915 14916 14917 14918 14919 14920 14921 14922 14923 14924 14925 14926 14927 14928 14929 14930 14931 14932 14933 14934 14935 14936 14937 14938 14939 14940 14941 14942 14943 14944 14945 14946 14947 14948 14949 14950 14951 14952 14953 14954 14955 14956 14957 14958 14959 14960 14961 14962 14963 14964 14965 14966 14967 14968 14969 14970 14971 14972 14973 14974 14975 14976 14977 14978 14979 14980 14981 14982 14983 14984 14985 14986 14987 14988 14989 14990 14991 14992 14993 14994 14995 14996 14997 14998 14999 15000
    
      return self
    }
    
    Request.prototype.jar = function (jar) {
      var self = this
      var cookies
    
      if (self._redirect.redirectsFollowed === 0) {
        self.originalCookieHeader = self.getHeader('cookie')
      }
    
      if (!jar) {
        // disable cookies
        cookies = false
        self._disableCookies = true
      } else {
        var targetCookieJar = (jar && jar.getCookieString) ? jar : globalCookieJar
        var urihref = self.uri.href
        // fetch cookie in the Specified host
        if (targetCookieJar) {
          cookies = targetCookieJar.getCookieString(urihref)
        }
      }
    
      // if need cookie and cookie is not empty
      if (cookies && cookies.length) {
        if (self.originalCookieHeader) {
          // Don't overwrite existing Cookie header
          self.setHeader('cookie', self.originalCookieHeader + '; ' + cookies)
        } else {
          self.setHeader('cookie', cookies)
        }
      }
      self._jar = jar
      return self
    }
    
    // Stream API
    Request.prototype.pipe = function (dest, opts) {
      var self = this
    
      if (self.response) {
        if (self._destdata) {
          self.emit('error', new Error('You cannot pipe after data has been emitted from the response.'))
        } else if (self._ended) {
          self.emit('error', new Error('You cannot pipe after the response has been ended.'))
        } else {
          stream.Stream.prototype.pipe.call(self, dest, opts)
          self.pipeDest(dest)
          return dest
        }
      } else {
        self.dests.push(dest)
        stream.Stream.prototype.pipe.call(self, dest, opts)
        return dest
      }
    }
    Request.prototype.write = function () {
      var self = this
      if (self._aborted) { return }
    
      if (!self._started) {
        self.start()
      }
      if (self.req) {
        return self.req.write.apply(self.req, arguments)
      }
    }
    Request.prototype.end = function (chunk) {
      var self = this
      if (self._aborted) { return }
    
      if (chunk) {
        self.write(chunk)
      }
      if (!self._started) {
        self.start()
      }
      if (self.req) {
        self.req.end()
      }
    }
    Request.prototype.pause = function () {
      var self = this
      if (!self.responseContent) {
        self._paused = true
      } else {
        self.responseContent.pause.apply(self.responseContent, arguments)
      }
    }
    Request.prototype.resume = function () {
      var self = this
      if (!self.responseContent) {
        self._paused = false
      } else {
        self.responseContent.resume.apply(self.responseContent, arguments)
      }
    }
    Request.prototype.destroy = function () {
      var self = this
      if (!self._ended) {
        self.end()
      } else if (self.response) {
        self.response.destroy()
      }
    }
    
    Request.defaultProxyHeaderWhiteList =
      Tunnel.defaultProxyHeaderWhiteList.slice()
    
    Request.defaultProxyHeaderExclusiveList =
      Tunnel.defaultProxyHeaderExclusiveList.slice()
    
    // Exports
    
    Request.prototype.toJSON = requestToJSON
    module.exports = Request
    
    
    /***/ }),
    /* 98 */
    /***/ (function(module, exports) {
    
    module.exports = require("http");
    
    /***/ }),
    /* 99 */
    /***/ (function(module, exports) {
    
    module.exports = require("https");
    
    /***/ }),
    /* 100 */
    /***/ (function(module, exports) {
    
    module.exports = require("stream");
    
    /***/ }),
    /* 101 */
    /***/ (function(module, exports) {
    
    module.exports = require("zlib");
    
    /***/ }),
    /* 102 */
    /***/ (function(module, exports, __webpack_require__) {
    
    
    /*!
     *  Copyright 2010 LearnBoost <dev@learnboost.com>
     *
     * Licensed under the Apache License, Version 2.0 (the "License");
     * you may not use this file except in compliance with the License.
     * You may obtain a copy of the License at
     *
     *     http://www.apache.org/licenses/LICENSE-2.0
     *
     * Unless required by applicable law or agreed to in writing, software
     * distributed under the License is distributed on an "AS IS" BASIS,
     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     * See the License for the specific language governing permissions and
     * limitations under the License.
     */
    
    /**
     * Module dependencies.
     */
    
    var crypto = __webpack_require__(94)
      , parse = __webpack_require__(83).parse
      ;
    
    /**
     * Valid keys.
     */
    
    var keys = 
      [ 'acl'
      , 'location'
      , 'logging'
      , 'notification'
      , 'partNumber'
      , 'policy'
      , 'requestPayment'
      , 'torrent'
      , 'uploadId'
      , 'uploads'
      , 'versionId'
      , 'versioning'
      , 'versions'
      , 'website'
      ]
    
    /**
     * Return an "Authorization" header value with the given `options`
     * in the form of "AWS <key>:<signature>"
     *
     * @param {Object} options
     * @return {String}
     * @api private
     */
    
    function authorization (options) {
      return 'AWS ' + options.key + ':' + sign(options)
    }
    
    module.exports = authorization
    module.exports.authorization = authorization
    
    /**
     * Simple HMAC-SHA1 Wrapper
     *
     * @param {Object} options
     * @return {String}
     * @api private
     */ 
    
    function hmacSha1 (options) {
      return crypto.createHmac('sha1', options.secret).update(options.message).digest('base64')
    }
    
    module.exports.hmacSha1 = hmacSha1
    
    /**
     * Create a base64 sha1 HMAC for `options`. 
     * 
     * @param {Object} options
     * @return {String}
     * @api private
     */
    
    function sign (options) {
      options.message = stringToSign(options)
      return hmacSha1(options)
    }
    module.exports.sign = sign
    
    /**
     * Create a base64 sha1 HMAC for `options`. 
     *
     * Specifically to be used with S3 presigned URLs
     * 
     * @param {Object} options
     * @return {String}
     * @api private
     */
    
    function signQuery (options) {
      options.message = queryStringToSign(options)
      return hmacSha1(options)
    }
    module.exports.signQuery= signQuery
    
    /**
     * Return a string for sign() with the given `options`.
     *
     * Spec:
     * 
     *    <verb>\n
     *    <md5>\n
     *    <content-type>\n
     *    <date>\n
     *    [headers\n]
     *    <resource>
     *
     * @param {Object} options
     * @return {String}
     * @api private
     */
    
    function stringToSign (options) {
      var headers = options.amazonHeaders || ''
      if (headers) headers += '\n'
      var r = 
        [ options.verb
        , options.md5
        , options.contentType
        , options.date ? options.date.toUTCString() : ''
        , headers + options.resource
        ]
      return r.join('\n')
    }
    module.exports.stringToSign = stringToSign
    
    /**
     * Return a string for sign() with the given `options`, but is meant exclusively
     * for S3 presigned URLs
     *
     * Spec:
     * 
     *    <date>\n
     *    <resource>
     *
     * @param {Object} options
     * @return {String}
     * @api private
     */
    
    function queryStringToSign (options){
      return 'GET\n\n\n' + options.date + '\n' + options.resource
    }
    module.exports.queryStringToSign = queryStringToSign
    
    /**
     * Perform the following:
     *
     *  - ignore non-amazon headers
     *  - lowercase fields
     *  - sort lexicographically
     *  - trim whitespace between ":"
     *  - join with newline
     *
     * @param {Object} headers
     * @return {String}
     * @api private
     */
    
    function canonicalizeHeaders (headers) {
      var buf = []
        , fields = Object.keys(headers)
        ;
      for (var i = 0, len = fields.length; i < len; ++i) {
        var field = fields[i]
          , val = headers[field]
          , field = field.toLowerCase()
          ;
        if (0 !== field.indexOf('x-amz')) continue
        buf.push(field + ':' + val)
      }
      return buf.sort().join('\n')
    }
    module.exports.canonicalizeHeaders = canonicalizeHeaders
    
    /**
     * Perform the following:
     *
     *  - ignore non sub-resources
     *  - sort lexicographically
     *
     * @param {String} resource
     * @return {String}
     * @api private
     */
    
    function canonicalizeResource (resource) {
      var url = parse(resource, true)
        , path = url.pathname
        , buf = []
        ;
    
      Object.keys(url.query).forEach(function(key){
        if (!~keys.indexOf(key)) return
        var val = '' == url.query[key] ? '' : '=' + encodeURIComponent(url.query[key])
        buf.push(key + val)
      })
    
      return path + (buf.length ? '?' + buf.sort().join('&') : '')
    }
    module.exports.canonicalizeResource = canonicalizeResource
    
    
    /***/ }),
    /* 103 */
    /***/ (function(module, exports, __webpack_require__) {
    
    var aws4 = exports,
        url = __webpack_require__(83),
        querystring = __webpack_require__(104),
        crypto = __webpack_require__(94),
        lru = __webpack_require__(105),
        credentialsCache = lru(1000)
    
    // http://docs.amazonwebservices.com/general/latest/gr/signature-version-4.html
    
    function hmac(key, string, encoding) {
      return crypto.createHmac('sha256', key).update(string, 'utf8').digest(encoding)
    }
    
    function hash(string, encoding) {
      return crypto.createHash('sha256').update(string, 'utf8').digest(encoding)
    }
    
    // This function assumes the string has already been percent encoded
    function encodeRfc3986(urlEncodedString) {
      return urlEncodedString.replace(/[!'()*]/g, function(c) {
        return '%' + c.charCodeAt(0).toString(16).toUpperCase()
      })
    }
    
    // request: { path | body, [host], [method], [headers], [service], [region] }
    // credentials: { accessKeyId, secretAccessKey, [sessionToken] }
    function RequestSigner(request, credentials) {
    
      if (typeof request === 'string') request = url.parse(request)
    
      var headers = request.headers = (request.headers || {}),
          hostParts = this.matchHost(request.hostname || request.host || headers.Host || headers.host)
    
      this.request = request
      this.credentials = credentials || this.defaultCredentials()
    
      this.service = request.service || hostParts[0] || ''
      this.region = request.region || hostParts[1] || 'us-east-1'
    
      // SES uses a different domain from the service name
      if (this.service === 'email') this.service = 'ses'
    
      if (!request.method && request.body)
        request.method = 'POST'
    
      if (!headers.Host && !headers.host) {
        headers.Host = request.hostname || request.host || this.createHost()
    
        // If a port is specified explicitly, use it as is
        if (request.port)
          headers.Host += ':' + request.port
      }
      if (!request.hostname && !request.host)
        request.hostname = headers.Host || headers.host
    
      this.isCodeCommitGit = this.service === 'codecommit' && request.method === 'GIT'
    }
    
    RequestSigner.prototype.matchHost = function(host) {
      var match = (host || '').match(/([^\.]+)\.(?:([^\.]*)\.)?amazonaws\.com(\.cn)?$/)
      var hostParts = (match || []).slice(1, 3)
    
      // ES's hostParts are sometimes the other way round, if the value that is expected
      // to be region equals ‘es’ switch them back
      // e.g. search-cluster-name-aaaa00aaaa0aaa0aaaaaaa0aaa.us-east-1.es.amazonaws.com
      if (hostParts[1] === 'es')
        hostParts = hostParts.reverse()
    
      return hostParts
    }
    
    // http://docs.aws.amazon.com/general/latest/gr/rande.html
    RequestSigner.prototype.isSingleRegion = function() {
      // Special case for S3 and SimpleDB in us-east-1
      if (['s3', 'sdb'].indexOf(this.service) >= 0 && this.region === 'us-east-1') return true
    
      return ['cloudfront', 'ls', 'route53', 'iam', 'importexport', 'sts']
        .indexOf(this.service) >= 0
    }
    
    RequestSigner.prototype.createHost = function() {
      var region = this.isSingleRegion() ? '' :
            (this.service === 's3' && this.region !== 'us-east-1' ? '-' : '.') + this.region,
          service = this.service === 'ses' ? 'email' : this.service
      return service + region + '.amazonaws.com'
    }
    
    RequestSigner.prototype.prepareRequest = function() {
      this.parsePath()
    
      var request = this.request, headers = request.headers, query
    
      if (request.signQuery) {
    
        this.parsedPath.query = query = this.parsedPath.query || {}
    
        if (this.credentials.sessionToken)
          query['X-Amz-Security-Token'] = this.credentials.sessionToken
    
        if (this.service === 's3' && !query['X-Amz-Expires'])
          query['X-Amz-Expires'] = 86400
    
        if (query['X-Amz-Date'])
          this.datetime = query['X-Amz-Date']
        else
          query['X-Amz-Date'] = this.getDateTime()
    
        query['X-Amz-Algorithm'] = 'AWS4-HMAC-SHA256'
        query['X-Amz-Credential'] = this.credentials.accessKeyId + '/' + this.credentialString()
        query['X-Amz-SignedHeaders'] = this.signedHeaders()
    
      } else {
    
        if (!request.doNotModifyHeaders && !this.isCodeCommitGit) {
          if (request.body && !headers['Content-Type'] && !headers['content-type'])
            headers['Content-Type'] = 'application/x-www-form-urlencoded; charset=utf-8'
    
          if (request.body && !headers['Content-Length'] && !headers['content-length'])
            headers['Content-Length'] = Buffer.byteLength(request.body)
    
          if (this.credentials.sessionToken && !headers['X-Amz-Security-Token'] && !headers['x-amz-security-token'])
            headers['X-Amz-Security-Token'] = this.credentials.sessionToken
    
          if (this.service === 's3' && !headers['X-Amz-Content-Sha256'] && !headers['x-amz-content-sha256'])
            headers['X-Amz-Content-Sha256'] = hash(this.request.body || '', 'hex')
    
          if (headers['X-Amz-Date'] || headers['x-amz-date'])
            this.datetime = headers['X-Amz-Date'] || headers['x-amz-date']
          else
            headers['X-Amz-Date'] = this.getDateTime()
        }
    
        delete headers.Authorization
        delete headers.authorization
      }
    }
    
    RequestSigner.prototype.sign = function() {
      if (!this.parsedPath) this.prepareRequest()
    
      if (this.request.signQuery) {
        this.parsedPath.query['X-Amz-Signature'] = this.signature()
      } else {
        this.request.headers.Authorization = this.authHeader()
      }
    
      this.request.path = this.formatPath()
    
      return this.request
    }
    
    RequestSigner.prototype.getDateTime = function() {
      if (!this.datetime) {
        var headers = this.request.headers,
          date = new Date(headers.Date || headers.date || new Date)
    
        this.datetime = date.toISOString().replace(/[:\-]|\.\d{3}/g, '')
    
        // Remove the trailing 'Z' on the timestamp string for CodeCommit git access
        if (this.isCodeCommitGit) this.datetime = this.datetime.slice(0, -1)
      }
      return this.datetime
    }
    
    RequestSigner.prototype.getDate = function() {
      return this.getDateTime().substr(0, 8)
    }
    
    RequestSigner.prototype.authHeader = function() {
      return [
        'AWS4-HMAC-SHA256 Credential=' + this.credentials.accessKeyId + '/' + this.credentialString(),
        'SignedHeaders=' + this.signedHeaders(),
        'Signature=' + this.signature(),
      ].join(', ')
    }
    
    RequestSigner.prototype.signature = function() {
      var date = this.getDate(),
          cacheKey = [this.credentials.secretAccessKey, date, this.region, this.service].join(),
          kDate, kRegion, kService, kCredentials = credentialsCache.get(cacheKey)
      if (!kCredentials) {
        kDate = hmac('AWS4' + this.credentials.secretAccessKey, date)
        kRegion = hmac(kDate, this.region)
        kService = hmac(kRegion, this.service)
        kCredentials = hmac(kService, 'aws4_request')
        credentialsCache.set(cacheKey, kCredentials)
      }
      return hmac(kCredentials, this.stringToSign(), 'hex')
    }
    
    RequestSigner.prototype.stringToSign = function() {
      return [
        'AWS4-HMAC-SHA256',
        this.getDateTime(),
        this.credentialString(),
        hash(this.canonicalString(), 'hex'),
      ].join('\n')
    }
    
    RequestSigner.prototype.canonicalString = function() {
      if (!this.parsedPath) this.prepareRequest()
    
      var pathStr = this.parsedPath.path,
          query = this.parsedPath.query,
          headers = this.request.headers,
          queryStr = '',
          normalizePath = this.service !== 's3',
          decodePath = this.service === 's3' || this.request.doNotEncodePath,
          decodeSlashesInPath = this.service === 's3',
          firstValOnly = this.service === 's3',
          bodyHash
    
      if (this.service === 's3' && this.request.signQuery) {
        bodyHash = 'UNSIGNED-PAYLOAD'
      } else if (this.isCodeCommitGit) {
        bodyHash = ''
      } else {
        bodyHash = headers['X-Amz-Content-Sha256'] || headers['x-amz-content-sha256'] ||
          hash(this.request.body || '', 'hex')
      }
    
      if (query) {
        queryStr = encodeRfc3986(querystring.stringify(Object.keys(query).sort().reduce(function(obj, key) {
          if (!key) return obj
          obj[key] = !Array.isArray(query[key]) ? query[key] :
            (firstValOnly ? query[key][0] : query[key].slice().sort())
          return obj
        }, {})))
      }
      if (pathStr !== '/') {
        if (normalizePath) pathStr = pathStr.replace(/\/{2,}/g, '/')
        pathStr = pathStr.split('/').reduce(function(path, piece) {
          if (normalizePath && piece === '..') {
            path.pop()
          } else if (!normalizePath || piece !== '.') {
            if (decodePath) piece = decodeURIComponent(piece)
            path.push(encodeRfc3986(encodeURIComponent(piece)))
          }
          return path
        }, []).join('/')
        if (pathStr[0] !== '/') pathStr = '/' + pathStr
        if (decodeSlashesInPath) pathStr = pathStr.replace(/%2F/g, '/')
      }
    
      return [
        this.request.method || 'GET',
        pathStr,
        queryStr,
        this.canonicalHeaders() + '\n',
        this.signedHeaders(),
        bodyHash,
      ].join('\n')
    }
    
    RequestSigner.prototype.canonicalHeaders = function() {
      var headers = this.request.headers
      function trimAll(header) {
        return header.toString().trim().replace(/\s+/g, ' ')
      }
      return Object.keys(headers)
        .sort(function(a, b) { return a.toLowerCase() < b.toLowerCase() ? -1 : 1 })
        .map(function(key) { return key.toLowerCase() + ':' + trimAll(headers[key]) })
        .join('\n')
    }
    
    RequestSigner.prototype.signedHeaders = function() {
      return Object.keys(this.request.headers)
        .map(function(key) { return key.toLowerCase() })
        .sort()
        .join(';')
    }
    
    RequestSigner.prototype.credentialString = function() {
      return [
        this.getDate(),
        this.region,
        this.service,
        'aws4_request',
      ].join('/')
    }
    
    RequestSigner.prototype.defaultCredentials = function() {
      var env = process.env
      return {
        accessKeyId: env.AWS_ACCESS_KEY_ID || env.AWS_ACCESS_KEY,
        secretAccessKey: env.AWS_SECRET_ACCESS_KEY || env.AWS_SECRET_KEY,
        sessionToken: env.AWS_SESSION_TOKEN,
      }
    }
    
    RequestSigner.prototype.parsePath = function() {
      var path = this.request.path || '/',
          queryIx = path.indexOf('?'),
          query = null
    
      if (queryIx >= 0) {
        query = querystring.parse(path.slice(queryIx + 1))
        path = path.slice(0, queryIx)
      }
    
      // S3 doesn't always encode characters > 127 correctly and
      // all services don't encode characters > 255 correctly
      // So if there are non-reserved chars (and it's not already all % encoded), just encode them all
      if (/[^0-9A-Za-z!'()*\-._~%/]/.test(path)) {
        path = path.split('/').map(function(piece) {
          return encodeURIComponent(decodeURIComponent(piece))
        }).join('/')
      }
    
      this.parsedPath = {
        path: path,
        query: query,
      }
    }
    
    RequestSigner.prototype.formatPath = function() {
      var path = this.parsedPath.path,
          query = this.parsedPath.query
    
      if (!query) return path
    
      // Services don't support empty query string keys
      if (query[''] != null) delete query['']
    
      return path + '?' + encodeRfc3986(querystring.stringify(query))
    }
    
    aws4.RequestSigner = RequestSigner
    
    aws4.sign = function(request, credentials) {
      return new RequestSigner(request, credentials).sign()
    }
    
    
    /***/ }),
    /* 104 */
    /***/ (function(module, exports) {
    
    module.exports = require("querystring");
    
    /***/ }),
    /* 105 */
    /***/ (function(module, exports) {
    
    module.exports = function(size) {
      return new LruCache(size)
    }
    
    function LruCache(size) {
      this.capacity = size | 0
      this.map = Object.create(null)
      this.list = new DoublyLinkedList()
    }
    
    LruCache.prototype.get = function(key) {
      var node = this.map[key]
      if (node == null) return undefined
      this.used(node)
      return node.val
    }
    
    LruCache.prototype.set = function(key, val) {
      var node = this.map[key]
      if (node != null) {
        node.val = val
      } else {
        if (!this.capacity) this.prune()
        if (!this.capacity) return false
        node = new DoublyLinkedNode(key, val)
        this.map[key] = node
        this.capacity--
      }
      this.used(node)
      return true
    }
    
    LruCache.prototype.used = function(node) {
      this.list.moveToFront(node)
    }
    
    LruCache.prototype.prune = function() {
      var node = this.list.pop()
      if (node != null) {
        delete this.map[node.key]
        this.capacity++
      }
    }
    
    
    function DoublyLinkedList() {
      this.firstNode = null
      this.lastNode = null
    }
    
    DoublyLinkedList.prototype.moveToFront = function(node) {
      if (this.firstNode == node) return
    
      this.remove(node)
    
      if (this.firstNode == null) {
        this.firstNode = node
        this.lastNode = node
        node.prev = null
        node.next = null
      } else {
        node.prev = null
        node.next = this.firstNode
        node.next.prev = node
        this.firstNode = node
      }
    }
    
    DoublyLinkedList.prototype.pop = function() {
      var lastNode = this.lastNode
      if (lastNode != null) {
        this.remove(lastNode)
      }
      return lastNode
    }
    
    DoublyLinkedList.prototype.remove = function(node) {
      if (this.firstNode == node) {
        this.firstNode = node.next
      } else if (node.prev != null) {
        node.prev.next = node.next
      }
      if (this.lastNode == node) {
        this.lastNode = node.prev
      } else if (node.next != null) {
        node.next.prev = node.prev
      }
    }
    
    
    function DoublyLinkedNode(key, val) {
      this.key = key
      this.val = val
      this.prev = null
      this.next = null
    }
    
    
    /***/ }),
    /* 106 */
    /***/ (function(module, exports, __webpack_require__) {
    
    // Copyright 2015 Joyent, Inc.
    
    var parser = __webpack_require__(107);
    var signer = __webpack_require__(149);
    var verify = __webpack_require__(156);
    var utils = __webpack_require__(110);
    
    
    
    ///--- API
    
    module.exports = {
    
      parse: parser.parseRequest,
      parseRequest: parser.parseRequest,
    
      sign: signer.signRequest,
      signRequest: signer.signRequest,
      createSigner: signer.createSigner,
      isSigner: signer.isSigner,
    
      sshKeyToPEM: utils.sshKeyToPEM,
      sshKeyFingerprint: utils.fingerprint,
      pemToRsaSSHKey: utils.pemToRsaSSHKey,
    
      verify: verify.verifySignature,
      verifySignature: verify.verifySignature,
      verifyHMAC: verify.verifyHMAC
    };
    
    
    /***/ }),
    /* 107 */
    /***/ (function(module, exports, __webpack_require__) {
    
    // Copyright 2012 Joyent, Inc.  All rights reserved.
    
    var assert = __webpack_require__(108);
    var util = __webpack_require__(9);
    var utils = __webpack_require__(110);
    
    
    
    ///--- Globals
    
    var HASH_ALGOS = utils.HASH_ALGOS;
    var PK_ALGOS = utils.PK_ALGOS;
    var HttpSignatureError = utils.HttpSignatureError;
    var InvalidAlgorithmError = utils.InvalidAlgorithmError;
    var validateAlgorithm = utils.validateAlgorithm;
    
    var State = {
      New: 0,
      Params: 1
    };
    
    var ParamsState = {
      Name: 0,
      Quote: 1,
      Value: 2,
      Comma: 3
    };
    
    
    ///--- Specific Errors
    
    
    function ExpiredRequestError(message) {
      HttpSignatureError.call(this, message, ExpiredRequestError);
    }
    util.inherits(ExpiredRequestError, HttpSignatureError);
    
    
    function InvalidHeaderError(message) {
      HttpSignatureError.call(this, message, InvalidHeaderError);
    }
    util.inherits(InvalidHeaderError, HttpSignatureError);
    
    
    function InvalidParamsError(message) {
      HttpSignatureError.call(this, message, InvalidParamsError);
    }
    util.inherits(InvalidParamsError, HttpSignatureError);
    
    
    function MissingHeaderError(message) {
      HttpSignatureError.call(this, message, MissingHeaderError);
    }
    util.inherits(MissingHeaderError, HttpSignatureError);
    
    function StrictParsingError(message) {
      HttpSignatureError.call(this, message, StrictParsingError);
    }
    util.inherits(StrictParsingError, HttpSignatureError);
    
    ///--- Exported API
    
    module.exports = {
    
      /**
       * Parses the 'Authorization' header out of an http.ServerRequest object.
       *
       * Note that this API will fully validate the Authorization header, and throw
       * on any error.  It will not however check the signature, or the keyId format
       * as those are specific to your environment.  You can use the options object
       * to pass in extra constraints.
       *
       * As a response object you can expect this:
       *
       *     {
       *       "scheme": "Signature",
       *       "params": {
       *         "keyId": "foo",
       *         "algorithm": "rsa-sha256",
       *         "headers": [
       *           "date" or "x-date",
       *           "digest"
       *         ],
       *         "signature": "base64"
       *       },
       *       "signingString": "ready to be passed to crypto.verify()"
       *     }
       *
       * @param {Object} request an http.ServerRequest.
       * @param {Object} options an optional options object with:
       *                   - clockSkew: allowed clock skew in seconds (default 300).
       *                   - headers: required header names (def: date or x-date)
       *                   - algorithms: algorithms to support (default: all).
       *                   - strict: should enforce latest spec parsing
       *                             (default: false).
       * @return {Object} parsed out object (see above).
       * @throws {TypeError} on invalid input.
       * @throws {InvalidHeaderError} on an invalid Authorization header error.
       * @throws {InvalidParamsError} if the params in the scheme are invalid.
       * @throws {MissingHeaderError} if the params indicate a header not present,
       *                              either in the request headers from the params,
       *                              or not in the params from a required header
       *                              in options.
       * @throws {StrictParsingError} if old attributes are used in strict parsing
       *                              mode.
       * @throws {ExpiredRequestError} if the value of date or x-date exceeds skew.
       */
      parseRequest: function parseRequest(request, options) {
        assert.object(request, 'request');
        assert.object(request.headers, 'request.headers');
        if (options === undefined) {
          options = {};
        }
        if (options.headers === undefined) {
          options.headers = [request.headers['x-date'] ? 'x-date' : 'date'];
        }
        assert.object(options, 'options');
        assert.arrayOfString(options.headers, 'options.headers');
        assert.optionalFinite(options.clockSkew, 'options.clockSkew');
    
        var authzHeaderName = options.authorizationHeaderName || 'authorization';
    
        if (!request.headers[authzHeaderName]) {
          throw new MissingHeaderError('no ' + authzHeaderName + ' header ' +
                                       'present in the request');
        }
    
        options.clockSkew = options.clockSkew || 300;
    
    
        var i = 0;
        var state = State.New;
        var substate = ParamsState.Name;
        var tmpName = '';
        var tmpValue = '';
    
        var parsed = {
          scheme: '',
          params: {},
          signingString: ''
        };
    
        var authz = request.headers[authzHeaderName];
        for (i = 0; i < authz.length; i++) {
          var c = authz.charAt(i);
    
          switch (Number(state)) {
    
          case State.New:
            if (c !== ' ') parsed.scheme += c;
            else state = State.Params;
            break;