Exemplo n.º 1
0
        public void ProtoMap3()
        {
            // Sample: ProtoMap3
            HttpTarget target = new HttpTarget();

            target.Headers["X-Custom-Header1"] = "Value1";
            target.Headers["X-Custom-Header2"] = "Value2";
            // End sample
        }
Exemplo n.º 2
0
        public async Task <AbstractTarget> GetTargetAsync()
        {
            HttpWebRequest req = WebRequest.CreateHttp(Uri);

            req.Method    = "HEAD";
            req.KeepAlive = false;
            using (var resp = (HttpWebResponse)await req.GetResponseAsync())
            {
                // abort the request
                if (req != null)
                {
                    req.Abort();
                }
                // get suggested name from url
                string suggestedName = Path.GetFileName(Uri.ToString());
                if (!IsFileNameValid(suggestedName))
                {
                    suggestedName = Path.GetRandomFileName();
                }
                string extension = Path.GetExtension(suggestedName);
                // guess the extension fron content type
                string contentType = (resp.ContentType ?? string.Empty)
                                     .Split(';', StringSplitOptions.None)[0];
                if (contentType.Length == 0)
                {
                    contentType = "text/html";
                }
                // don't modify extension if content type is application/octet-stream
                if (!contentType.Equals("application/octet-stream"))
                {
                    if (!MimeTypesMap.GetMimeType(extension).Equals(contentType))
                    {
                        var suggestedExtension = MimeTypesMap.GetExtension(contentType);
                        if (suggestedExtension.Length > 0 &&
                            !Path.GetExtension(suggestedName).Equals(suggestedExtension))
                        {
                            suggestedName = suggestedName + "." + suggestedExtension;
                        }
                    }
                }

                // check if rangable
                AbstractTarget target = null;
                if (resp.ContentLength <= 0)
                {
                    target = new HttpTarget(Uri, suggestedName);
                }
                else
                {
                    target = new HttpRangableTarget(Uri, suggestedName, resp.ContentLength);
                }
                return(target);
            }
        }
Exemplo n.º 3
0
 public void ProtoMap2()
 {
     // Sample: ProtoMap2
     HttpTarget target = new HttpTarget
     {
         Headers =
         {
             ["X-Custom-Header1"] = "Value1",
             ["X-Custom-Header2"] = "Value2",
         }
     };
     // End sample
 }
Exemplo n.º 4
0
 public void ProtoMap1()
 {
     // Sample: ProtoMap1
     HttpTarget target = new HttpTarget
     {
         Headers =
         {
             { "X-Custom-Header1", "Value1" },
             { "X-Custom-Header2", "Value2" },
         }
     };
     // End sample
 }