public void Apply(ICloudFilesRequest request) { request.Method = "POST"; request.Headers.Add(Constants.X_CDN_ENABLED, _isCdnEnabled.Capitalize()); request.Headers.Add(Constants.X_LOG_RETENTION, _isLoggingEnabled.Capitalize()); if(_timeToLiveInSeconds > -1) request.Headers.Add(Constants.X_CDN_TTL, _timeToLiveInSeconds.ToString()); }
/// <summary> /// Applies the appropiate method to the specified request. /// </summary> /// <param name="request">The request.</param> public void Apply(ICloudFilesRequest request) { request.Method = "PUT"; if ((_metadata != null) && (_metadata.Count > 0)) { foreach (var m in _metadata.Where(m => (!String.IsNullOrEmpty(m.Key)) && (!String.IsNullOrEmpty(m.Value)))) { if (m.Key.ToLower().StartsWith(Constants.X_CONTAINTER_META_DATA_HEADER)) { // make sure the metadata item isn't just the container metadata prefix string if (m.Key.Length > Constants.X_CONTAINTER_META_DATA_HEADER.Length) { // If the caller already added the container metadata prefix string, // add their key as is. request.Headers.Add(m.Key, m.Value); } } else { request.Headers.Add(Constants.X_CONTAINTER_META_DATA_HEADER + m.Key, m.Value); } } } }
/// <summary> /// Applies the appropiate method and headers to the specified request for this implementation. /// </summary> /// <param name="request">The request.</param> public void Apply(ICloudFilesRequest request) { request.Method = "POST"; string enabled = _loggingenabled ? "True" : "False"; request.Headers.Add("X-Log-Retention", enabled); }
/// <summary> /// Applies the corresponding method and headers for this authentication request. /// </summary> /// <param name="request">The request.</param> public void Apply(ICloudFilesRequest request) { request.Method = "GET"; request.Headers.Add(Constants.X_AUTH_USER, _userCredentials.Username.Encode()); request.Headers.Add(Constants.X_AUTH_KEY, _userCredentials.Api_access_key.Encode()); request.Timeout = this.Timeout; }
/// <summary> /// Applies the apropiate method to the specified request. /// </summary> /// <param name="request">The request.</param> public void Apply(ICloudFilesRequest request) { request.Method = "DELETE"; if(_emailAddresses != null && _emailAddresses.Length > 0) { request.Headers.Add(Constants.X_PURGE_EMAIL, string.Join(",", _emailAddresses)); } }
public void Apply(ICloudFilesRequest request) { request.Method = "POST"; request.Headers.Add(Constants.X_CDN_ENABLED, _isCdnEnabled.Capitalize()); request.Headers.Add(Constants.X_LOG_RETENTION, _isLoggingEnabled.Capitalize()); if(_timeToLiveInSeconds > -1) request.Headers.Add(Constants.X_CDN_TTL, _timeToLiveInSeconds.ToString()); if(!String.IsNullOrEmpty(_agentacl)) request.Headers.Add(Constants.X_USER_AGENT_ACL, _agentacl); if (!String.IsNullOrEmpty(_refacl)) request.Headers.Add(Constants.X_REFERRER_ACL, _refacl); }
private WebHeaderCollection GetHeaderCollection(ICloudFilesRequest request, out HttpStatusCode statusCode, out Stream responseStream) { httpResponse = request.GetResponse(); var headerCollection = httpResponse.Headers; statusCode = httpResponse.StatusCode; responseStream = httpResponse.GetResponseStream(); return headerCollection; }
private void AttachMetadataToHeaders(ICloudFilesRequest request) { foreach (var pair in metadata) { if (pair.Key.Length > Constants.MAXIMUM_META_KEY_LENGTH) throw new MetaKeyLengthException("The meta key length exceeds the maximum length of " + Constants.MAXIMUM_META_KEY_LENGTH); if (pair.Value.Length > Constants.MAXIMUM_META_VALUE_LENGTH) throw new MetaValueLengthException("The meta value length exceeds the maximum length of " + Constants.MAXIMUM_META_VALUE_LENGTH); request.Headers.Add(Constants.META_DATA_HEADER + pair.Key, pair.Value); } }
public GetStorageItemResponse CreateStorageItem(ICloudFilesRequest request) { HttpStatusCode statusCode; Stream responseStream; WebHeaderCollection headerCollection = GetHeaderCollection(request, out statusCode, out responseStream); var response = new GetStorageItemResponse() { Headers = headerCollection, Status = statusCode, ContentStream = responseStream }; return response; }
/// <summary> /// /// </summary> /// <param name="request"></param> /// <returns></returns> public IResponseWithContentBody Create(ICloudFilesRequest request) { HttpStatusCode statusCode; Stream responseStream; WebHeaderCollection headerCollection = GetHeaderCollection(request, out statusCode, out responseStream); var response = new CloudFilesResponseWithContentBody() { Headers = headerCollection, Status = statusCode, ContentStream = responseStream }; return response; }
/// <summary> /// /// </summary> /// <param name="request"></param> /// <returns></returns> public ICloudFilesResponse Create(ICloudFilesRequest request) { // this may be very very wrong look at tests closely // if (request.ContentLength>0) // throw new InvalidResponseTypeException( // "The request type is of IRequestWithContentBody. Content body is expected with this request. "); Log.Debug(this, OutputRequestInformation(request)); var response = request.GetResponse(); Log.Debug(this, OutputResponseInformation(response)); response.Close(); return response; }
private string OutputRequestInformation(ICloudFilesRequest request) { var output = new StringBuilder(); output.AppendLine("REQUEST"); output.Append("Request URL: "); output.AppendLine(request.RequestUri.ToString()); output.Append("Method: "); output.AppendLine(request.Method); output.AppendLine("Headers: "); foreach (var key in request.Headers.AllKeys) { output.Append(key); output.Append(": "); output.Append(request.Headers[key]); output.AppendLine(); } return output.ToString(); }
/// <summary> /// Applies the apropiate method to the specified request. /// </summary> /// <param name="request">The request.</param> public void Apply(ICloudFilesRequest request) { request.Method = "HEAD"; }
public void Apply(ICloudFilesRequest request) { request.Method = "POST"; AttachMetadataToHeaders(request); }
/// <summary> /// Applies the appropiate properties to the specified request for this implementation. /// </summary> /// <param name="request">The request.</param> public void Apply(ICloudFilesRequest request) { request.Method = "PUT"; request.ContentType = "application/directory"; request.SetContent(new MemoryStream(new byte[0]), delegate { }); }
private void VerifyAndSplitRangeHeader(ICloudFilesRequest request, string value) { Regex r = new Regex("^[0-9]*[-][0-9]*$"); if (!r.IsMatch(value)) throw new InvalidRangeHeaderException( "The range must be of the format integer-integer where either integer field is optional. "); string [] ranged = value.Split('-'); if (ranged.Length >= 1 && ranged[0].Length > 0) request.RangeFrom = int.Parse(ranged[0]); if (ranged.Length == 2 && ranged[1].Length > 0) { if (ranged[0].Length == 0) request.RangeTo = -int.Parse(ranged[1]); else request.RangeTo = int.Parse(ranged[1]); } }
private void AddRequestFieldHeadersToRequestHeaders(Dictionary<RequestHeaderFields, string> requestHeaderFields, ICloudFilesRequest request) { if (requestHeaderFields == null || requestHeaderFields.Count == 0) return; foreach(KeyValuePair<RequestHeaderFields, string> item in requestHeaderFields) { if(!IsSpecialRequestHeaderField(item.Key)) request.Headers.Add(EnumHelper.GetDescription(item.Key), item.Value); if (item.Key == RequestHeaderFields.IfUnmodifiedSince) { request.Headers.Add(EnumHelper.GetDescription(item.Key), String.Format("{0:r}", ParserDateTimeHttpHeader(item.Value))); continue; } if (item.Key == RequestHeaderFields.IfModifiedSince) { request.IfModifiedSince = ParserDateTimeHttpHeader(item.Value); ; continue; } if (item.Key == RequestHeaderFields.Range) { VerifyAndSplitRangeHeader(request,item.Value); continue; } } }
public void Apply(ICloudFilesRequest request) { request.Method = "GET"; AddRequestFieldHeadersToRequestHeaders(_requestHeaderFields, request); }
private void AddAuthHeaderToRequest(ICloudFilesRequest cfrequest, string authtoken) { cfrequest.Headers.Add(Constants.X_AUTH_TOKEN, HttpUtility.UrlEncode(authtoken)); }
/// <summary> /// Applies the apropiate method to the specified request. /// </summary> /// <param name="request">The request.</param> public void Apply(ICloudFilesRequest request) { request.Method = "COPY"; request.Headers.Add("Destination", "/" + _containerName.Encode() + "/" + _destItemName.StripSlashPrefix().Encode()); }
/// <summary> /// Applies the corresponding method and headers for this authentication request. /// </summary> /// <param name="request">The request.</param> public void Apply(ICloudFilesRequest request) { request.Method = "GET"; request.Headers.Add(Constants.X_AUTH_USER, _userCredentials.Username.Encode()); request.Headers.Add(Constants.X_AUTH_KEY, _userCredentials.Api_access_key.Encode()); }
public void Apply(ICloudFilesRequest request) { request.Method = "DELETE"; }
/// <summary> /// Applies the appropiate method and headers to the specified request for this implementation. /// </summary> /// <param name="request">The request.</param> public void Apply(ICloudFilesRequest request) { request.Method = "GET"; AddRequestFieldHeadersToRequestHeaders(_requestHeaderFields, request); }
/// <summary> /// Applies the appropiate properties to the specified request for this implementation. /// </summary> /// <param name="request">The request.</param> public void Apply(ICloudFilesRequest request) { _fileToSend.Position = 0; request.Method = "PUT"; if (_metadata != null && _metadata.Count > 0) { foreach (var m in _metadata) { if ((String.IsNullOrEmpty(m.Key)) || (String.IsNullOrEmpty(m.Value))) { continue; } if (m.Key.StartsWith(Constants.META_DATA_HEADER, StringComparison.InvariantCultureIgnoreCase)) { // make sure the metadata item isn't just the container metadata prefix string if (m.Key.Length > Constants.META_DATA_HEADER.Length) { // If the caller already added the container metadata prefix string, // add their key as is. request.Headers.Add(m.Key, m.Value); } } else { request.Headers.Add(Constants.META_DATA_HEADER + m.Key, m.Value); } } } request.AllowWriteStreamBuffering = false; request.ContentType = ContentType(); request.SetContent(_fileToSend, Progress); }
/// <summary> /// Applies the appropiate properties to the specified request for this implementation. /// </summary> /// <param name="request">The request.</param> public void Apply(ICloudFilesRequest request) { request.Method = "PUT"; if (_metadata != null && _metadata.Count > 0) { foreach (var s in _metadata.Keys) { request.Headers.Add(Constants.META_DATA_HEADER + s, _metadata[s]); } } request.AllowWriteStreamBuffering = false; request.ContentType = ContentType(); request.SetContent(_fileToSend, Progress); }
public void Apply(ICloudFilesRequest request) { request.Method = "GET"; }
public void Apply(ICloudFilesRequest request) { request.Method = "PUT"; request.Headers.Add(Constants.X_CDN_ENABLED, "true".Capitalize()); if (_timeToLiveInSeconds > -1) { request.Headers.Add(Constants.X_CDN_TTL, _timeToLiveInSeconds.ToString()); } }