Skip to content

Commit 820e3f9

Browse files
committed
ServiceStack now has full REST support complete with Integration tests. Refactored all endpoints to bind on IHttpRequest and IHttpResponse to prepare for OWIN and future hosting supports on different platfroms.
1 parent eb1e239 commit 820e3f9

33 files changed

+5059
-3651
lines changed

src/ServiceStack.Common.4.5.resharper.user

Lines changed: 2015 additions & 1888 deletions
Large diffs are not rendered by default.
Lines changed: 64 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,65 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.IO;
4-
using ServiceStack.Configuration;
5-
using ServiceStack.Service;
6-
using ServiceStack.ServiceHost;
7-
8-
namespace ServiceStack.Common.Web
9-
{
10-
public class CompressedResult
11-
: IStreamWriter, IHasOptions
12-
{
13-
public const int Adler32ChecksumLength = 4;
14-
15-
public const string DefaultContentType = MimeTypes.Xml;
16-
17-
public byte[] Contents { get; private set; }
18-
19-
public Dictionary<string, string> Headers { get; private set; }
20-
21-
public IDictionary<string, string> Options
22-
{
23-
get { return this.Headers; }
24-
}
25-
26-
public CompressedResult(byte[] contents)
27-
: this(contents, CompressionTypes.Deflate) { }
28-
29-
public CompressedResult(byte[] contents, string compressionType)
30-
: this(contents, compressionType, DefaultContentType) { }
31-
32-
public CompressedResult(byte[] contents, string compressionType, string contentMimeType)
33-
{
34-
if (!CompressionTypes.IsValid(compressionType))
35-
{
36-
throw new ArgumentException("Must be either 'deflate' or 'gzip'", compressionType);
37-
}
38-
39-
this.Contents = contents;
40-
this.Headers = new Dictionary<string, string> {
41-
{ HttpHeaders.ContentType, contentMimeType },
42-
{ HttpHeaders.ContentEncoding, compressionType },
43-
};
44-
}
45-
46-
public void WriteTo(Stream stream)
47-
{
48-
stream.Write(this.Contents, Adler32ChecksumLength, this.Contents.Length - Adler32ChecksumLength);
49-
stream.Flush();
50-
}
51-
52-
}
1+
using System;
2+
using System.Collections.Generic;
3+
using System.IO;
4+
using System.Net;
5+
using ServiceStack.Service;
6+
using ServiceStack.ServiceHost;
7+
8+
namespace ServiceStack.Common.Web
9+
{
10+
public class CompressedResult
11+
: IStreamWriter, IHttpResult
12+
{
13+
public const int Adler32ChecksumLength = 4;
14+
15+
public const string DefaultContentType = MimeTypes.Xml;
16+
17+
public byte[] Contents { get; private set; }
18+
19+
public string ContentType { get; set; }
20+
21+
public Dictionary<string, string> Headers { get; private set; }
22+
23+
public HttpStatusCode StatusCode { get; set; }
24+
25+
public object Response
26+
{
27+
get { return this.Contents; }
28+
set { throw new NotImplementedException(); }
29+
}
30+
31+
public IDictionary<string, string> Options
32+
{
33+
get { return this.Headers; }
34+
}
35+
36+
public CompressedResult(byte[] contents)
37+
: this(contents, CompressionTypes.Deflate) { }
38+
39+
public CompressedResult(byte[] contents, string compressionType)
40+
: this(contents, compressionType, DefaultContentType) { }
41+
42+
public CompressedResult(byte[] contents, string compressionType, string contentMimeType)
43+
{
44+
if (!CompressionTypes.IsValid(compressionType))
45+
{
46+
throw new ArgumentException("Must be either 'deflate' or 'gzip'", compressionType);
47+
}
48+
49+
this.StatusCode = HttpStatusCode.OK;
50+
this.ContentType = contentMimeType;
51+
52+
this.Contents = contents;
53+
this.Headers = new Dictionary<string, string> {
54+
{ HttpHeaders.ContentEncoding, compressionType },
55+
};
56+
}
57+
58+
public void WriteTo(Stream stream)
59+
{
60+
stream.Write(this.Contents, Adler32ChecksumLength, this.Contents.Length - Adler32ChecksumLength);
61+
stream.Flush();
62+
}
63+
64+
}
5365
}

src/ServiceStack.Common/Web/ContentType.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ public class ContentType
77
{
88
public const string HeaderContentType = "Content-Type";
99

10+
public const string MultiPartFormData = "multipart/form-data";
11+
1012
public const string Html = "text/html";
1113

1214
public const string Xml = "application/xml";
Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
1-
namespace ServiceStack.Common.Web
2-
{
3-
public static class HttpHeaders
4-
{
5-
public const string AcceptEncoding = "Accept-Encoding";
6-
7-
public const string ContentType = "Content-Type";
8-
9-
public const string ContentEncoding = "Content-Encoding";
10-
11-
public const string ContentLength = "Content-Length";
12-
13-
public const string Location = "Location";
14-
}
1+
namespace ServiceStack.Common.Web
2+
{
3+
public static class HttpHeaders
4+
{
5+
public const string Accept = "Accept";
6+
7+
public const string AcceptEncoding = "Accept-Encoding";
8+
9+
public const string ContentType = "Content-Type";
10+
11+
public const string ContentEncoding = "Content-Encoding";
12+
13+
public const string ContentLength = "Content-Length";
14+
15+
public const string Location = "Location";
16+
}
1517
}
Lines changed: 84 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -1,82 +1,85 @@
1-
using System.Collections.Generic;
2-
using System.Runtime.Serialization;
3-
using ServiceStack.Logging;
4-
using ServiceStack.Logging.Support.Logging;
5-
using ServiceStack.ServiceHost;
6-
using ServiceStack.Text;
7-
8-
namespace ServiceStack.WebHost.Endpoints
9-
{
10-
public class EndpointHostConfig
11-
{
12-
private const string DefaultUsageExamplesBaseUri =
13-
"http://code.google.com/p/servicestack/source/browse/trunk/doc/UsageExamples";
14-
15-
public EndpointHostConfig()
16-
{
17-
this.UsageExamplesBaseUri = DefaultUsageExamplesBaseUri;
18-
this.ServiceEndpointsMetadataConfig = new ServiceEndpointsMetadataConfig {
19-
DefaultMetadataUri = "Public/Metadata",
20-
Soap11 = new SoapMetadataConfig("Public/Soap11/SyncReply.svc", "Public/Soap11/AsyncOneWay.svc", "Public/Soap11/Metadata", "Public/Soap11/Wsdl"),
21-
Soap12 = new SoapMetadataConfig("Public/Soap12/SyncReply.svc", "Public/Soap12/AsyncOneWay.svc", "Public/Soap12/Metadata", "Public/Soap12/Wsdl"),
22-
Xml = new MetadataConfig("Public/Xml/SyncReply", "Public/Xml/AsyncOneWay", "Public/Xml/Metadata"),
23-
Json = new MetadataConfig("Public/Json/SyncReply", "Public/Json/AsyncOneWay", "Public/Json/Metadata"),
24-
Jsv = new MetadataConfig("Public/Jsv/SyncReply", "Public/Jsv/AsyncOneWay", "Public/Jsv/Metadata"),
25-
};
26-
this.LogFactory = new NullLogFactory();
27-
this.EnableAccessRestrictions = true;
28-
29-
this.GlobalResponseHeaders = new Dictionary<string, string>
30-
{ { "X-Powered-By", Env.ServerUserAgent } };
31-
}
32-
33-
public IServiceController ServiceController { get; set; }
34-
public string UsageExamplesBaseUri { get; set; }
35-
public string ServiceName { get; set; }
36-
public ServiceEndpointsMetadataConfig ServiceEndpointsMetadataConfig { get; set; }
37-
public ILogFactory LogFactory { get; set; }
38-
public bool EnableAccessRestrictions { get; set; }
39-
public bool UseBclJsonSerializers { get; set; }
40-
public Dictionary<string, string> GlobalResponseHeaders { get; set; }
41-
42-
private string defaultOperationNamespace;
43-
public string DefaultOperationNamespace
44-
{
45-
get
46-
{
47-
if (this.defaultOperationNamespace == null)
48-
{
49-
this.defaultOperationNamespace = GetDefaultNamespace();
50-
}
51-
return this.defaultOperationNamespace;
52-
}
53-
set
54-
{
55-
this.defaultOperationNamespace = value;
56-
}
57-
}
58-
59-
private string GetDefaultNamespace()
60-
{
61-
if (!string.IsNullOrEmpty(this.defaultOperationNamespace)
62-
|| this.ServiceController == null) return null;
63-
64-
foreach (var operationType in this.ServiceController.OperationTypes)
65-
{
66-
var attrs = operationType.GetCustomAttributes(
67-
typeof(DataContractAttribute), false);
68-
69-
if (attrs.Length <= 0) continue;
70-
71-
var attr = (DataContractAttribute)attrs[0];
72-
73-
if (string.IsNullOrEmpty(attr.Namespace)) continue;
74-
75-
return attr.Namespace;
76-
}
77-
78-
return null;
79-
}
80-
81-
}
1+
using System.Collections.Generic;
2+
using System.Runtime.Serialization;
3+
using ServiceStack.Logging;
4+
using ServiceStack.Logging.Support.Logging;
5+
using ServiceStack.ServiceHost;
6+
using ServiceStack.Text;
7+
using ServiceStack.WebHost.Endpoints.Support;
8+
9+
namespace ServiceStack.WebHost.Endpoints
10+
{
11+
public class EndpointHostConfig
12+
{
13+
private const string DefaultUsageExamplesBaseUri =
14+
"http://code.google.com/p/servicestack/source/browse/trunk/doc/UsageExamples";
15+
16+
public EndpointHostConfig()
17+
{
18+
this.UsageExamplesBaseUri = DefaultUsageExamplesBaseUri;
19+
this.ServiceEndpointsMetadataConfig = new ServiceEndpointsMetadataConfig {
20+
DefaultMetadataUri = "Public/Metadata",
21+
Soap11 = new SoapMetadataConfig("Public/Soap11/SyncReply.svc", "Public/Soap11/AsyncOneWay.svc", "Public/Soap11/Metadata", "Public/Soap11/Wsdl"),
22+
Soap12 = new SoapMetadataConfig("Public/Soap12/SyncReply.svc", "Public/Soap12/AsyncOneWay.svc", "Public/Soap12/Metadata", "Public/Soap12/Wsdl"),
23+
Xml = new MetadataConfig("Public/Xml/SyncReply", "Public/Xml/AsyncOneWay", "Public/Xml/Metadata"),
24+
Json = new MetadataConfig("Public/Json/SyncReply", "Public/Json/AsyncOneWay", "Public/Json/Metadata"),
25+
Jsv = new MetadataConfig("Public/Jsv/SyncReply", "Public/Jsv/AsyncOneWay", "Public/Jsv/Metadata"),
26+
};
27+
this.LogFactory = new NullLogFactory();
28+
this.EnableAccessRestrictions = true;
29+
this.DefaultContentType = ContentType.Json;
30+
31+
this.GlobalResponseHeaders = new Dictionary<string, string>
32+
{ { "X-Powered-By", Env.ServerUserAgent } };
33+
}
34+
35+
public IServiceController ServiceController { get; set; }
36+
public string UsageExamplesBaseUri { get; set; }
37+
public string ServiceName { get; set; }
38+
public string DefaultContentType { get; set; }
39+
public ServiceEndpointsMetadataConfig ServiceEndpointsMetadataConfig { get; set; }
40+
public ILogFactory LogFactory { get; set; }
41+
public bool EnableAccessRestrictions { get; set; }
42+
public bool UseBclJsonSerializers { get; set; }
43+
public Dictionary<string, string> GlobalResponseHeaders { get; set; }
44+
45+
private string defaultOperationNamespace;
46+
public string DefaultOperationNamespace
47+
{
48+
get
49+
{
50+
if (this.defaultOperationNamespace == null)
51+
{
52+
this.defaultOperationNamespace = GetDefaultNamespace();
53+
}
54+
return this.defaultOperationNamespace;
55+
}
56+
set
57+
{
58+
this.defaultOperationNamespace = value;
59+
}
60+
}
61+
62+
private string GetDefaultNamespace()
63+
{
64+
if (!string.IsNullOrEmpty(this.defaultOperationNamespace)
65+
|| this.ServiceController == null) return null;
66+
67+
foreach (var operationType in this.ServiceController.OperationTypes)
68+
{
69+
var attrs = operationType.GetCustomAttributes(
70+
typeof(DataContractAttribute), false);
71+
72+
if (attrs.Length <= 0) continue;
73+
74+
var attr = (DataContractAttribute)attrs[0];
75+
76+
if (string.IsNullOrEmpty(attr.Namespace)) continue;
77+
78+
return attr.Namespace;
79+
}
80+
81+
return null;
82+
}
83+
84+
}
8285
}

0 commit comments

Comments
 (0)