Ejemplo n.º 1
0
 public static string HtmlNow()
 {
     return(HttpTime.Date2TimeHtml(DateTime.Now));
 }
Ejemplo n.º 2
0
        public void PrepareSend()
        {
            HeadStream = (Stream) new MemoryStream();
            StreamWriter headWriter = new StreamWriter(HeadStream, Encoding.ASCII);

            string codeReason = HttpConst.CodeReasons[Code];

            headWriter.WriteLine("{0} {1} {2}",
                                 HttpConst.HttpVersion, (int)Code, codeReason);

            if (Location != null)
            {
                headWriter.WriteLine("Location: {0}", Location);
            }

            headWriter.WriteLine("Server: {0}", WebConfig.ServerVersion);
            headWriter.WriteLine("Connection: {0}", Connection);
            headWriter.WriteLine("Date: {0}", HttpTime.HtmlNow());

            if (Body != null && Body.HasContent)
            {
                if (Body.ContentEncoding != ContentEncodings.NORMAL)
                {
                    string cenc = "";

                    switch (Body.ContentEncoding)
                    {
                    case ContentEncodings.GZIP:
                        cenc = "gzip";
                        break;

                    case ContentEncodings.DEFLATE:
                        cenc = "deflate";
                        break;
                    }

                    headWriter.WriteLine("Content-Encoding: {0}", cenc);
                }

                if (Body.ContentEncoding == ContentEncodings.GZIP)
                {
                    MemoryStream body = new MemoryStream();
                    GZip.Compress(Body.ContentStream, body);
                    Body.ContentStream = body;
                }

                if (LastModified != null)
                {
                    headWriter.WriteLine("Last-Modified: {0}",
                                         HttpTime.Date2TimeHtml(LastModified));
                }

                headWriter.Write("Content-Type: {0}", Body.ContentType);

                if (Body.ContentType.StartsWith("text") && Body.CharSet.Length > 0)
                {
                    headWriter.Write("; charset={0}", Body.CharSet);
                }

                headWriter.WriteLine();

                if (Body.ContentDisposition != null && Body.ContentDisposition.Length > 0)
                {
                    headWriter.WriteLine("Content-Disposition: {0}", Body.ContentDisposition);
                }

                headWriter.WriteLine("Content-Length: {0}", Body.Length);

                // BUG para MSIE para imagenes en CSS
                if (Body.ContentType.StartsWith("image") && Request.IsMSIEBrowser)
                {
                    headWriter.WriteLine("Expires: {0}", HttpTime.Date2TimeHtml(DateTime.Now.AddHours(2)));
                }

                headWriter.WriteLine("Cache-Control: {0}", "public, must-revalidate, max-age = 1");
            }
            else
            {
                headWriter.WriteLine("Content-Length: {0}", 0);
            }

            foreach (object item in Head.Fields.Values)
            {
                var field = (HttpField)item;
                switch (field.Name)
                {
                default:
                    headWriter.WriteLine("{0}: {1}", field.Name, field.Value);
                    break;
                }
            }

            headWriter.WriteLine();
            headWriter.Flush();
        }
Ejemplo n.º 3
0
 /// <summary>
 /// redondear una fecha para que sea compatible con las fechas que llegan desde mensajes
 /// HTTP que no tienen milisegundos
 /// </summary>
 /// <param name="dateTime"></param>
 /// <returns></returns>
 public static DateTime RoundDate(DateTime dateTime)
 {
     return(HttpTime.TimeHtml2Date(HttpTime.Date2TimeHtml(dateTime)));;
 }