Esempio n. 1
0
 public GetResponse( WebRequest request ) :
     base(request)
 {
     SortedList metadata = extractMetadata( response );
     byte [] data = Utils.slurpInputStream( response.GetResponseStream() );
     this.obj = new S3Object( data, metadata );
 }
Esempio n. 2
0
 public Response createBucket( string bucket, SortedList headers )
 {
     S3Object obj = new S3Object("", null);
     WebRequest request = makeRequest("PUT", bucket, "", headers, obj);
     request.ContentLength = 0;
     request.GetRequestStream().Close();
     return new Response(request);
 }
Esempio n. 3
0
        /// <summary>
        /// Make a new WebRequest
        /// </summary>
        /// <param name="method">The HTTP method to use (GET, PUT, DELETE)</param>
        /// <param name="bucket">The bucket name for this request</param>
        /// <param name="key">The key this request is for</param>
        /// <param name="headers">A map of string to string representing the HTTP headers to pass (can be null)</param>
        /// <param name="obj">S3Object that is to be written (can be null).</param>
        private WebRequest makeRequest( string method, string bucket, string key, SortedList query, SortedList headers, S3Object obj )
        {
            StringBuilder url = new StringBuilder();
            url.Append( isSecure ? "https://" : "http://" );
            url.Append( Utils.buildUrlBase(server, port, bucket, callingFormat) );
            if ( key != null && key.Length != 0 ) {
                url.Append( key );
            }

            // build the query string parameter
            url.Append( Utils.convertQueryListToQueryString( query ) );

            WebRequest req = WebRequest.Create( url.ToString() );
            if ( req is HttpWebRequest ) {
                HttpWebRequest httpReq = req as HttpWebRequest;
                httpReq.AllowWriteStreamBuffering = false;
            }
            req.Method = method;

            addHeaders( req, headers );
            if ( obj != null ) addMetadataHeaders( req, obj.Metadata );
            addAuthHeader( req, bucket, key, query );

            return req;
            
        }
Esempio n. 4
0
 /// <summary>
 /// Make a new WebRequest with an S3Object.
 /// </summary>
 private WebRequest makeRequest(string method, string bucket, string key, SortedList headers, S3Object obj)
 {
     return makeRequest(method, bucket, key, new SortedList(), headers, obj);
 }
Esempio n. 5
0
        /// <summary>
        /// Write a new ACL for a given object
        /// </summary>
        /// <param name="bucket">The name of the bucket where the object lives or the
        /// name of the bucket to change the ACL if key is null.</param>
        /// <param name="key">The name of the key to use; can be null.</param>
        /// <param name="aclXMLDoc">An XML representation of the ACL as a string.</param>
        /// <param name="headers">A map of string to string representing the HTTP headers to pass (can be null)</param>
        public Response putACL(string bucket, string key, string aclXMLDoc, SortedList headers)
        {
            S3Object obj = new S3Object( aclXMLDoc, null );
            if ( key == null ) key = "";

            SortedList query = new SortedList();
            query.Add("acl", "");

            WebRequest request = makeRequest("PUT", bucket, encodeKeyForSignature(key), query, headers, obj);
            request.ContentLength = aclXMLDoc.Length;

            request.GetRequestStream().Write(obj.Bytes, 0, obj.Bytes.Length);
            request.GetRequestStream().Close();

            return new Response(request);
        }
Esempio n. 6
0
        /// <summary>
        /// Write a new logging xml document for a given bucket
        /// </summary>
        /// <param name="bucket">The name of the bucket to enable/disable logging on</param>
        /// <param name="loggingXMLDoc">The xml representation of the logging configuration as a String.</param>
        /// <param name="headers">A map of string to string representing the HTTP headers to pass (can be null)</param>
        public Response putBucketLogging(string bucket, string loggingXMLDoc, SortedList headers)
        {
            S3Object obj = new S3Object(loggingXMLDoc, null);

            SortedList query = new SortedList();
            query.Add("logging", "");
            WebRequest request = makeRequest("PUT", bucket, "", query, headers, obj);
            request.ContentLength = loggingXMLDoc.Length;

            request.GetRequestStream().Write(obj.Bytes, 0, obj.Bytes.Length);
            request.GetRequestStream().Close();

            return new Response(request);
        }
Esempio n. 7
0
        /// <summary>
        /// Writes an object to S3.
        /// </summary>
        /// <param name="bucket">The name of the bucket to which the object will be added.</param>
        /// <param name="key">The name of the key to use</param>
        /// <param name="obj">An S3Object containing the data to write.</param>
        /// <param name="headers">A map of string to string representing the HTTP headers to pass (can be null)</param>
        public Response put( string bucket, string key, S3Object obj, SortedList headers )
        {
            WebRequest request = makeRequest("PUT", bucket, encodeKeyForSignature(key), headers, obj);
            request.ContentLength = obj.Bytes.Length;

            using (Stream _stream = request.GetRequestStream()) {
                _stream.Write(obj.Bytes, 0, obj.Bytes.Length);
                return new Response(request);
            }
        }