System.Messaging \
System.ServiceProcess \
System.Drawing.Design \
+ Mono.Http \
Microsoft.Vsa
# Microsoft.JScript \
--- /dev/null
+2003-07-24 Gonzalo Paniagua Javier <gonzalo@ximian.com>
+
+ Initial check-in.
+
--- /dev/null
+thisdir = class/Mono.Http
+SUBDIRS =
+include ../../build/rules.make
+
+LIBRARY = Mono.Http.dll
+LIB_MCS_FLAGS = -r:$(corlib) -r:System.dll -r:System.Xml.dll \
+ -r:System.Web.dll -r:ICSharpCode.SharpZipLib.dll
+
+NO_TEST = yes
+
+include ../../build/library.make
--- /dev/null
+Mono.Http/AcceptEncodingConfig.cs
+Mono.Http/AcceptEncodingModule.cs
+Mono.Http/AcceptEncodingSectionHandler.cs
+Mono.Http/GZipWriteFilter.cs
--- /dev/null
+//
+// AcceptEncodingConfig.cs
+//
+// Authors:
+// Gonzalo Paniagua Javier (gonzalo@ximian.com)
+//
+// (c) 2003 Ximian, Inc (http://www.ximian.com)
+//
+
+using System;
+using System.Collections;
+using System.Collections.Specialized;
+using System.IO;
+using System.Web;
+
+namespace Mono.Http
+{
+ public class AcceptEncodingConfig
+ {
+ Hashtable tbl = CollectionsUtil.CreateCaseInsensitiveHashtable ();
+
+ public AcceptEncodingConfig () : this (null)
+ {
+ }
+
+ public AcceptEncodingConfig (AcceptEncodingConfig parent)
+ {
+ if (parent == null)
+ return;
+
+ // FIXME: copy parent's config
+ }
+
+ public void Add (string encoding, string type)
+ {
+ tbl [encoding] = Type.GetType (type);
+ }
+
+ public bool SetFilter (HttpResponse response, string acceptEncoding)
+ {
+ if (acceptEncoding == null)
+ return false;
+
+ acceptEncoding = acceptEncoding.Trim ();
+ if (acceptEncoding == "")
+ return false;
+
+ string [] parts = null;
+ if (acceptEncoding.IndexOf (';') != -1)
+ parts = acceptEncoding.Split (';');
+ else
+ parts = acceptEncoding.Split (',');
+
+ string encoding;
+ float weight = 0.0f;
+ float current = 0.0f;
+ Type type = null;
+ string name = null;
+ int i = 0;
+ foreach (string s in parts) {
+ encoding = null;
+ ParseValue (s, ref encoding, ref weight);
+ if (encoding != null && weight > current && tbl.Contains (encoding)) {
+ type = tbl [encoding] as Type;
+ current = weight;
+ name = encoding;
+ }
+ i++;
+ }
+
+ if (type == null)
+ return false;
+
+ Stream filter = response.Filter;
+ response.Filter = (Stream) Activator.CreateInstance (type, new object [] {filter});
+ response.AppendHeader ("Content-Encoding", name);
+ return true;
+ }
+
+ public void Clear ()
+ {
+ tbl.Clear ();
+ }
+
+ static void ParseValue (string s, ref string encoding, ref float weight)
+ {
+ //FIXME: make it more spec compliant
+ string [] parts = s.Trim ().Split (',');
+ if (parts.Length == 1) {
+ encoding = parts [0].Trim ();
+ weight = 1.0f;
+ } else if (parts.Length == 2) {
+ encoding = parts [0].Trim ();
+ try {
+ int i = parts [1].IndexOf ('=');
+ if (i != -1)
+ weight = Convert.ToSingle (parts [1].Substring (i + 1));
+ } catch {
+ weight = 0.0f;
+ }
+ } else {
+ //ignore
+ }
+ }
+ }
+}
+
--- /dev/null
+//
+// AcceptEncodingModule.cs
+//
+// Authors:
+// Gonzalo Paniagua Javier (gonzalo@ximian.com)
+//
+// (c) 2003 Ximian, Inc (http://www.ximian.com)
+//
+
+using System;
+using System.Configuration;
+using System.IO;
+using System.Web;
+
+namespace Mono.Http
+{
+ public class AcceptEncodingModule : IHttpModule
+ {
+ static readonly string configSection = "mono.aspnet/acceptEncoding";
+ AcceptEncodingConfig config;
+
+ public void Init (HttpApplication app)
+ {
+ app.BeginRequest += new EventHandler (CheckIfAddFilter);
+ }
+
+ public void Dispose ()
+ {
+ }
+
+ void CheckIfAddFilter (object sender, EventArgs args)
+ {
+ HttpApplication app = (HttpApplication) sender;
+ HttpRequest request = app.Request;
+ HttpResponse response = app.Response;
+
+ //FIXME: fix this when config is cached
+ if (config == null)
+ //config = (AcceptEncodingConfig) app.Context.GetConfig (configSection);
+ config = (AcceptEncodingConfig) ConfigurationSettings.GetConfig (configSection);
+
+ config.SetFilter (response, request.Headers ["Accept-Encoding"]);
+ }
+ }
+}
+
--- /dev/null
+//
+// AcceptEncodingSectionHandler.cs
+//
+// Authors:
+// Gonzalo Paniagua Javier (gonzalo@ximian.com)
+//
+// (c) 2003 Ximian, Inc (http://www.ximian.com)
+//
+
+using System;
+using System.Configuration;
+using System.IO;
+using System.Xml;
+
+namespace Mono.Http
+{
+ public class AcceptEncodingSectionHandler : IConfigurationSectionHandler
+ {
+ public object Create (object parent, object configContext, XmlNode section)
+ {
+ AcceptEncodingConfig cfg = new AcceptEncodingConfig (parent as AcceptEncodingConfig);
+
+ if (section.Attributes != null && section.Attributes.Count != 0)
+ ThrowException ("Unrecognized attribute", section);
+
+ XmlNodeList nodes = section.ChildNodes;
+ foreach (XmlNode child in nodes) {
+ XmlNodeType ntype = child.NodeType;
+ if (ntype == XmlNodeType.Whitespace || ntype == XmlNodeType.Comment)
+ continue;
+
+ if (ntype != XmlNodeType.Element)
+ ThrowException ("Only elements allowed", child);
+
+ string name = child.Name;
+ if (name == "clear") {
+ if (child.Attributes != null && child.Attributes.Count != 0)
+ ThrowException ("Unrecognized attribute", child);
+
+ cfg.Clear ();
+ continue;
+ }
+
+ if (name != "add")
+ ThrowException ("Unexpected element", child);
+
+ string encoding = ExtractAttributeValue ("encoding", child, false);
+ string type = ExtractAttributeValue ("type", child, false);
+ string disabled = ExtractAttributeValue ("disabled", child, true);
+ if (disabled != null && disabled == "yes")
+ continue;
+
+ if (child.Attributes != null && child.Attributes.Count != 0)
+ ThrowException ("Unrecognized attribute", child);
+
+ cfg.Add (encoding, type);
+ }
+
+ return cfg;
+ }
+
+ static void ThrowException (string msg, XmlNode node)
+ {
+ if (node != null && node.Name != String.Empty)
+ msg = msg + " (node name: " + node.Name + ") ";
+
+ throw new ConfigurationException (msg, node);
+ }
+
+ static string ExtractAttributeValue (string attKey, XmlNode node, bool optional)
+ {
+ if (node.Attributes == null) {
+ if (optional)
+ return null;
+
+ ThrowException ("Required attribute not found: " + attKey, node);
+ }
+
+ XmlNode att = node.Attributes.RemoveNamedItem (attKey);
+ if (att == null) {
+ if (optional)
+ return null;
+ ThrowException ("Required attribute not found: " + attKey, node);
+ }
+
+ string value = att.Value;
+ if (value == String.Empty) {
+ string opt = optional ? "Optional" : "Required";
+ ThrowException (opt + " attribute is empty: " + attKey, node);
+ }
+
+ return value;
+ }
+ }
+}
+
--- /dev/null
+2003-07-24 Gonzalo Paniagua Javier <gonzalo@ximian.com>
+
+ Initial check-in.
+
--- /dev/null
+//
+// GZipFilter.cs
+//
+// Authors:
+// Gonzalo Paniagua Javier (gonzalo@ximian.com)
+//
+// (c) 2003 Ximian, Inc (http://www.ximian.com)
+//
+
+using System;
+using System.IO;
+using ICSharpCode.SharpZipLib.GZip;
+
+namespace Mono.Http
+{
+ public class GZipWriteFilter : Stream
+ {
+ Stream baseStream;
+ GZipOutputStream st;
+
+ public GZipWriteFilter (Stream baseStream)
+ {
+ // baseStream is not ready yet for filtering and any attemp to write
+ // the gzip header will throw.
+ this.baseStream = baseStream;
+ }
+
+ public override bool CanRead {
+ get { return false; }
+ }
+
+ public override bool CanSeek {
+ get { return false; }
+ }
+
+ public override bool CanWrite {
+ get {
+ if (st == null)
+ return false;
+
+ return st.CanWrite;
+ }
+ }
+
+ public override long Length {
+ get { return 0; }
+ }
+
+ public override long Position {
+ get { return 0; }
+ set { }
+ }
+
+ public override void Flush ()
+ {
+ }
+
+ public override int Read (byte [] buffer, int offset, int count)
+ {
+ return 0;
+ }
+
+ public override long Seek (long offset, SeekOrigin origin)
+ {
+ return 0;
+ }
+
+ public override void SetLength (long value)
+ {
+ }
+
+ public override void Write (byte [] buffer, int offset, int count)
+ {
+ if (st == null)
+ st = new GZipOutputStream (baseStream);
+
+ st.Write (buffer, offset, count);
+ }
+
+ public override void Close ()
+ {
+ if (st == null)
+ return;
+
+ st.Finish ();
+ st = null;
+ base.Close ();
+ }
+ }
+}
+
--- /dev/null
+Mono.Http assembly
+--------------------
+This assembly holds a number of classes that provide additional features to
+existing Http protocol related ones, such as support for gzip compression of
+pages when hosting ASP.NET pages (xsp uses it) and others.
+
+Watch out the NEWS file.
+
+-Gonzalo
+