2 // OutgoingWebResponseContext.cs
5 // Atsushi Enomoto <atsushi@ximian.com>
7 // Copyright (C) 2008 Novell, Inc (http://www.novell.com)
9 // Permission is hereby granted, free of charge, to any person obtaining
10 // a copy of this software and associated documentation files (the
11 // "Software"), to deal in the Software without restriction, including
12 // without limitation the rights to use, copy, modify, merge, publish,
13 // distribute, sublicense, and/or sell copies of the Software, and to
14 // permit persons to whom the Software is furnished to do so, subject to
15 // the following conditions:
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
20 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 using System.Globalization;
31 using System.ServiceModel.Channels;
33 namespace System.ServiceModel.Web
35 public class OutgoingWebResponseContext
37 WebHeaderCollection headers;
39 string content_type, etag, location, status_desc;
40 DateTime last_modified;
41 HttpStatusCode status_code;
44 internal OutgoingWebResponseContext ()
48 internal void Apply (HttpResponseMessageProperty hp)
51 hp.Headers.Add (headers);
52 if (content_length != 0)
53 hp.Headers ["Content-Length"] = content_length.ToString (NumberFormatInfo.InvariantInfo);
54 if (content_type != null)
55 hp.Headers ["Content-Type"] = content_type;
57 hp.Headers ["ETag"] = etag;
59 hp.Headers ["Location"] = location;
60 if (last_modified != default (DateTime))
61 hp.Headers ["Last-Modified"] = last_modified.ToString ("R");
62 if (status_code != default (HttpStatusCode))
63 hp.StatusCode = status_code;
64 if (status_desc != null)
65 hp.StatusDescription = status_desc;
66 hp.SuppressEntityBody = suppress_body;
69 public long ContentLength {
70 get { return content_length; }
71 set { content_length = value; }
74 public string ContentType {
75 get { return content_type; }
76 set { content_type = value; }
84 public WebHeaderCollection Headers {
87 headers = new WebHeaderCollection ();
92 public DateTime LastModified {
93 get { return last_modified; }
94 set { last_modified = value; }
97 public string Location {
98 get { return location; }
99 set { location = value; }
102 public HttpStatusCode StatusCode {
103 get { return status_code; }
104 set { status_code = value; }
107 public string StatusDescription {
108 get { return status_desc; }
109 set { status_desc = value; }
112 public bool SuppressEntityBody {
113 get { return suppress_body; }
114 set { suppress_body = value; }
117 public void SetStatusAsCreated (Uri locationUri)
119 StatusCode = HttpStatusCode.Created;
120 Location = locationUri.AbsoluteUri;
123 public void SetStatusAsNotFound ()
125 StatusCode = HttpStatusCode.NotFound;
128 public void SetStatusAsNotFound (string description)
130 StatusCode = HttpStatusCode.NotFound;
131 StatusDescription = description;