git-off

git off handles large files in git repos
git clone https://noulin.net/git/git-off.git
Log | Files | Refs | README

http.js (6400B)


      1 var AWS = require('./core');
      2 var inherit = AWS.util.inherit;
      3 
      4 /**
      5  * The endpoint that a service will talk to, for example,
      6  * `'https://ec2.ap-southeast-1.amazonaws.com'`. If
      7  * you need to override an endpoint for a service, you can
      8  * set the endpoint on a service by passing the endpoint
      9  * object with the `endpoint` option key:
     10  *
     11  * ```javascript
     12  * var ep = new AWS.Endpoint('awsproxy.example.com');
     13  * var s3 = new AWS.S3({endpoint: ep});
     14  * s3.service.endpoint.hostname == 'awsproxy.example.com'
     15  * ```
     16  *
     17  * Note that if you do not specify a protocol, the protocol will
     18  * be selected based on your current {AWS.config} configuration.
     19  *
     20  * @!attribute protocol
     21  *   @return [String] the protocol (http or https) of the endpoint
     22  *     URL
     23  * @!attribute hostname
     24  *   @return [String] the host portion of the endpoint, e.g.,
     25  *     example.com
     26  * @!attribute host
     27  *   @return [String] the host portion of the endpoint including
     28  *     the port, e.g., example.com:80
     29  * @!attribute port
     30  *   @return [Integer] the port of the endpoint
     31  * @!attribute href
     32  *   @return [String] the full URL of the endpoint
     33  */
     34 AWS.Endpoint = inherit({
     35 
     36   /**
     37    * @overload Endpoint(endpoint)
     38    *   Constructs a new endpoint given an endpoint URL. If the
     39    *   URL omits a protocol (http or https), the default protocol
     40    *   set in the global {AWS.config} will be used.
     41    *   @param endpoint [String] the URL to construct an endpoint from
     42    */
     43   constructor: function Endpoint(endpoint, config) {
     44     AWS.util.hideProperties(this, ['slashes', 'auth', 'hash', 'search', 'query']);
     45 
     46     if (typeof endpoint === 'undefined' || endpoint === null) {
     47       throw new Error('Invalid endpoint: ' + endpoint);
     48     } else if (typeof endpoint !== 'string') {
     49       return AWS.util.copy(endpoint);
     50     }
     51 
     52     if (!endpoint.match(/^http/)) {
     53       var useSSL = config && config.sslEnabled !== undefined ?
     54         config.sslEnabled : AWS.config.sslEnabled;
     55       endpoint = (useSSL ? 'https' : 'http') + '://' + endpoint;
     56     }
     57 
     58     AWS.util.update(this, AWS.util.urlParse(endpoint));
     59 
     60     // Ensure the port property is set as an integer
     61     if (this.port) {
     62       this.port = parseInt(this.port, 10);
     63     } else {
     64       this.port = this.protocol === 'https:' ? 443 : 80;
     65     }
     66   }
     67 
     68 });
     69 
     70 /**
     71  * The low level HTTP request object, encapsulating all HTTP header
     72  * and body data sent by a service request.
     73  *
     74  * @!attribute method
     75  *   @return [String] the HTTP method of the request
     76  * @!attribute path
     77  *   @return [String] the path portion of the URI, e.g.,
     78  *     "/list/?start=5&num=10"
     79  * @!attribute headers
     80  *   @return [map<String,String>]
     81  *     a map of header keys and their respective values
     82  * @!attribute body
     83  *   @return [String] the request body payload
     84  * @!attribute endpoint
     85  *   @return [AWS.Endpoint] the endpoint for the request
     86  * @!attribute region
     87  *   @api private
     88  *   @return [String] the region, for signing purposes only.
     89  */
     90 AWS.HttpRequest = inherit({
     91 
     92   /**
     93    * @api private
     94    */
     95   constructor: function HttpRequest(endpoint, region, customUserAgent) {
     96     endpoint = new AWS.Endpoint(endpoint);
     97     this.method = 'POST';
     98     this.path = endpoint.path || '/';
     99     this.headers = {};
    100     this.body = '';
    101     this.endpoint = endpoint;
    102     this.region = region;
    103     this.setUserAgent(customUserAgent);
    104   },
    105 
    106   /**
    107    * @api private
    108    */
    109   setUserAgent: function setUserAgent(customUserAgent) {
    110     var prefix = AWS.util.isBrowser() ? 'X-Amz-' : '';
    111     var customSuffix = '';
    112     if (typeof customUserAgent === 'string' && customUserAgent) {
    113       customSuffix += ' ' + customUserAgent;
    114     }
    115     this.headers[prefix + 'User-Agent'] = AWS.util.userAgent() + customSuffix;
    116   },
    117 
    118   /**
    119    * @return [String] the part of the {path} excluding the
    120    *   query string
    121    */
    122   pathname: function pathname() {
    123     return this.path.split('?', 1)[0];
    124   },
    125 
    126   /**
    127    * @return [String] the query string portion of the {path}
    128    */
    129   search: function search() {
    130     var query = this.path.split('?', 2)[1];
    131     if (query) {
    132       query = AWS.util.queryStringParse(query);
    133       return AWS.util.queryParamsToString(query);
    134     }
    135     return '';
    136   }
    137 
    138 });
    139 
    140 /**
    141  * The low level HTTP response object, encapsulating all HTTP header
    142  * and body data returned from the request.
    143  *
    144  * @!attribute statusCode
    145  *   @return [Integer] the HTTP status code of the response (e.g., 200, 404)
    146  * @!attribute headers
    147  *   @return [map<String,String>]
    148  *      a map of response header keys and their respective values
    149  * @!attribute body
    150  *   @return [String] the response body payload
    151  * @!attribute [r] streaming
    152  *   @return [Boolean] whether this response is being streamed at a low-level.
    153  *     Defaults to `false` (buffered reads). Do not modify this manually, use
    154  *     {createUnbufferedStream} to convert the stream to unbuffered mode
    155  *     instead.
    156  */
    157 AWS.HttpResponse = inherit({
    158 
    159   /**
    160    * @api private
    161    */
    162   constructor: function HttpResponse() {
    163     this.statusCode = undefined;
    164     this.headers = {};
    165     this.body = undefined;
    166     this.streaming = false;
    167     this.stream = null;
    168   },
    169 
    170   /**
    171    * Disables buffering on the HTTP response and returns the stream for reading.
    172    * @return [Stream, XMLHttpRequest, null] the underlying stream object.
    173    *   Use this object to directly read data off of the stream.
    174    * @note This object is only available after the {AWS.Request~httpHeaders}
    175    *   event has fired. This method must be called prior to
    176    *   {AWS.Request~httpData}.
    177    * @example Taking control of a stream
    178    *   request.on('httpHeaders', function(statusCode, headers) {
    179    *     if (statusCode < 300) {
    180    *       if (headers.etag === 'xyz') {
    181    *         // pipe the stream, disabling buffering
    182    *         var stream = this.response.httpResponse.createUnbufferedStream();
    183    *         stream.pipe(process.stdout);
    184    *       } else { // abort this request and set a better error message
    185    *         this.abort();
    186    *         this.response.error = new Error('Invalid ETag');
    187    *       }
    188    *     }
    189    *   }).send(console.log);
    190    */
    191   createUnbufferedStream: function createUnbufferedStream() {
    192     this.streaming = true;
    193     return this.stream;
    194   }
    195 });
    196 
    197 
    198 AWS.HttpClient = inherit({});
    199 
    200 /**
    201  * @api private
    202  */
    203 AWS.HttpClient.getInstance = function getInstance() {
    204   if (this.singleton === undefined) {
    205     this.singleton = new this();
    206   }
    207   return this.singleton;
    208 };