diff options
| author | LukePulverenti Luke Pulverenti luke pulverenti <LukePulverenti Luke Pulverenti luke.pulverenti@gmail.com> | 2012-07-19 22:22:44 -0400 |
|---|---|---|
| committer | LukePulverenti Luke Pulverenti luke pulverenti <LukePulverenti Luke Pulverenti luke.pulverenti@gmail.com> | 2012-07-19 22:22:44 -0400 |
| commit | 80b3ad7bd20329e6a5bbf6eeb76af62c87434a7c (patch) | |
| tree | 81ab455261cf30fab4b932215211d8cd0e57547a /MediaBrowser.Net/Handlers/BaseHandler.cs | |
| parent | 6fbd5cf46407a212fadb52eee00c7ac7690430ea (diff) | |
Moved the http server to it's own assembly. added comments and made other minor re-organizations.
Diffstat (limited to 'MediaBrowser.Net/Handlers/BaseHandler.cs')
| -rw-r--r-- | MediaBrowser.Net/Handlers/BaseHandler.cs | 111 |
1 files changed, 111 insertions, 0 deletions
diff --git a/MediaBrowser.Net/Handlers/BaseHandler.cs b/MediaBrowser.Net/Handlers/BaseHandler.cs new file mode 100644 index 000000000..7a2bcffe9 --- /dev/null +++ b/MediaBrowser.Net/Handlers/BaseHandler.cs @@ -0,0 +1,111 @@ +using System;
+using System.Collections.Generic;
+using System.Collections.Specialized;
+using System.IO;
+using System.IO.Compression;
+
+namespace MediaBrowser.Net.Handlers
+{
+ public abstract class BaseHandler
+ {
+ /// <summary>
+ /// Response headers
+ /// </summary>
+ public IDictionary<string, string> Headers = new Dictionary<string, string>();
+
+ /// <summary>
+ /// The action to write the response to the output stream
+ /// </summary>
+ public Action<Stream> WriteStream { get; set; }
+
+ /// <summary>
+ /// The original RequestContext
+ /// </summary>
+ public RequestContext RequestContext { get; set; }
+
+ /// <summary>
+ /// The original QueryString
+ /// </summary>
+ protected NameValueCollection QueryString
+ {
+ get
+ {
+ return RequestContext.Request.QueryString;
+ }
+ }
+
+ /// <summary>
+ /// Gets the MIME type to include in the response headers
+ /// </summary>
+ public abstract string ContentType { get; }
+
+ /// <summary>
+ /// Gets the status code to include in the response headers
+ /// </summary>
+ public virtual int StatusCode
+ {
+ get
+ {
+ return 200;
+ }
+ }
+
+ /// <summary>
+ /// Gets the cache duration to include in the response headers
+ /// </summary>
+ public virtual TimeSpan CacheDuration
+ {
+ get
+ {
+ return TimeSpan.FromTicks(0);
+ }
+ }
+
+ /// <summary>
+ /// Gets the last date modified of the content being returned, if this can be determined.
+ /// This will be used to invalidate the cache, so it's not needed if CacheDuration is 0.
+ /// </summary>
+ public virtual DateTime? LastDateModified
+ {
+ get
+ {
+ return null;
+ }
+ }
+
+ public virtual bool GzipResponse
+ {
+ get
+ {
+ return true;
+ }
+ }
+
+ public BaseHandler()
+ {
+ WriteStream = s =>
+ {
+ WriteReponse(s);
+ s.Close();
+ };
+ }
+
+ private void WriteReponse(Stream stream)
+ {
+ if (GzipResponse)
+ {
+ using (GZipStream gzipStream = new GZipStream(stream, CompressionMode.Compress, false))
+ {
+ WriteResponseToOutputStream(gzipStream);
+ }
+ }
+ else
+ {
+ WriteResponseToOutputStream(stream);
+ }
+ }
+
+ protected abstract void WriteResponseToOutputStream(Stream stream);
+
+ }
+}
\ No newline at end of file |
