| | | 1 | | // Licensed to the .NET Foundation under one or more agreements. |
| | | 2 | | // The .NET Foundation licenses this file to you under the MIT license. |
| | | 3 | | |
| | | 4 | | using System; |
| | | 5 | | using System.Net; |
| | | 6 | | |
| | | 7 | | namespace CoreWCF.Channels |
| | | 8 | | { |
| | | 9 | | public sealed class HttpResponseMessageProperty : IMessageProperty |
| | | 10 | | { |
| | | 11 | | public const HttpStatusCode DefaultStatusCode = HttpStatusCode.OK; |
| | | 12 | | public const string DefaultStatusDescription = null; // null means use description from status code |
| | | 13 | | |
| | | 14 | | private WebHeaderCollection _originalHeaders; |
| | | 15 | | private HttpStatusCode _statusCode; |
| | | 16 | | private WebHeaderCollection _headers; |
| | | 17 | | |
| | | 18 | | /// <summary> |
| | | 19 | | /// Initializes a new instance of the HttpResponseMessageProperty class with no headers and the default status c |
| | | 20 | | /// </summary> |
| | | 21 | | public HttpResponseMessageProperty() |
| | 143 | 22 | | : this((WebHeaderCollection)null) |
| | | 23 | | { |
| | 143 | 24 | | } |
| | | 25 | | |
| | | 26 | | /// <summary> |
| | | 27 | | /// Initializes a new instance of the <see cref="HttpResponseMessageProperty"/> class. |
| | | 28 | | /// </summary> |
| | | 29 | | /// <param name="originalHeaders">The original headers. This collection will be copied so that the original is n |
| | 143 | 30 | | internal HttpResponseMessageProperty(WebHeaderCollection originalHeaders) |
| | | 31 | | { |
| | 143 | 32 | | _originalHeaders = originalHeaders; |
| | 143 | 33 | | _statusCode = DefaultStatusCode; |
| | 143 | 34 | | StatusDescription = DefaultStatusDescription; |
| | 143 | 35 | | } |
| | | 36 | | |
| | | 37 | | public const string Name = "httpResponse"; |
| | | 38 | | |
| | | 39 | | /// <summary> |
| | | 40 | | /// Gets a mutable list of headers. |
| | | 41 | | /// </summary> |
| | | 42 | | public WebHeaderCollection Headers |
| | | 43 | | { |
| | | 44 | | get |
| | | 45 | | { |
| | 378 | 46 | | if (_headers == null) |
| | | 47 | | { |
| | 143 | 48 | | _headers = new WebHeaderCollection(); |
| | 143 | 49 | | if (_originalHeaders != null) |
| | | 50 | | { |
| | 0 | 51 | | _headers.Add(_originalHeaders); |
| | 0 | 52 | | _originalHeaders = null; |
| | | 53 | | } |
| | | 54 | | } |
| | | 55 | | |
| | 378 | 56 | | return _headers; |
| | | 57 | | } |
| | | 58 | | } |
| | | 59 | | |
| | | 60 | | /// <summary> |
| | | 61 | | /// Gets or sets the HTTP status code. |
| | | 62 | | /// </summary> |
| | | 63 | | /// <value>The HTTP status code.</value> |
| | | 64 | | /// <exception cref="ArgumentOutOfRangeException">The status code is less than 100 or greater than 599</exceptio |
| | | 65 | | public HttpStatusCode StatusCode |
| | | 66 | | { |
| | | 67 | | get |
| | | 68 | | { |
| | 147 | 69 | | return _statusCode; |
| | | 70 | | } |
| | | 71 | | set |
| | | 72 | | { |
| | 113 | 73 | | int valueInt = (int)value; |
| | 113 | 74 | | if (valueInt < 100 || valueInt > 599) |
| | | 75 | | { |
| | 0 | 76 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(val |
| | 0 | 77 | | SR.Format(SR.ValueMustBeInRange, 100, 599))); |
| | | 78 | | } |
| | | 79 | | |
| | 113 | 80 | | _statusCode = value; |
| | 113 | 81 | | HasStatusCodeBeenSet = true; |
| | 113 | 82 | | } |
| | | 83 | | } |
| | | 84 | | |
| | 113 | 85 | | internal bool HasStatusCodeBeenSet { get; private set; } |
| | | 86 | | |
| | | 87 | | /// <summary> |
| | | 88 | | /// Gets or sets the HTTP status description. |
| | | 89 | | /// </summary> |
| | | 90 | | /// <value>The HTTP status description.</value> |
| | | 91 | | /// <remarks>If this returns null, use the default description for the current HttpStatusCode.</remarks> |
| | 288 | 92 | | public string StatusDescription { get; set; } |
| | | 93 | | |
| | | 94 | | /// <summary> |
| | | 95 | | /// Gets or sets a value indicating whether to suppress entity body. |
| | | 96 | | /// </summary> |
| | | 97 | | /// <remarks>If this is true, then the content-type will not be set.</remarks> |
| | 285 | 98 | | public bool SuppressEntityBody { get; set; } |
| | | 99 | | |
| | | 100 | | //Note currently in use. Remove? |
| | 0 | 101 | | public bool SuppressPreamble { get; set; } |
| | | 102 | | |
| | | 103 | | IMessageProperty IMessageProperty.CreateCopy() |
| | | 104 | | { |
| | 177 | 105 | | return this; |
| | | 106 | | } |
| | | 107 | | } |
| | | 108 | | } |