|
| 1 | +using System; |
| 2 | +using System.Collections.Generic; |
| 3 | + |
| 4 | +namespace GenHTTP.Api.Protocol |
| 5 | +{ |
| 6 | + |
| 7 | + public sealed class ResponseModifications |
| 8 | + { |
| 9 | + |
| 10 | + #region Get-/Setters |
| 11 | + |
| 12 | + public FlexibleResponseStatus? Status { get; } |
| 13 | + |
| 14 | + public FlexibleContentType? ContentType { get; } |
| 15 | + |
| 16 | + public List<Cookie>? Cookies { get; } |
| 17 | + |
| 18 | + public string? Encoding { get; } |
| 19 | + |
| 20 | + public DateTime? ExpiryDate { get; } |
| 21 | + |
| 22 | + public DateTime? ModificationDate { get; } |
| 23 | + |
| 24 | + public Dictionary<string, string>? Headers { get; } |
| 25 | + |
| 26 | + #endregion |
| 27 | + |
| 28 | + #region Initialization |
| 29 | + |
| 30 | + public ResponseModifications(FlexibleResponseStatus? status, FlexibleContentType? contentType, |
| 31 | + List<Cookie>? cookies, string? encoding, DateTime? expiryDate, DateTime? modificationDate, |
| 32 | + Dictionary<string, string>? headers) |
| 33 | + { |
| 34 | + Status = status; |
| 35 | + |
| 36 | + ContentType = contentType; |
| 37 | + Encoding = encoding; |
| 38 | + |
| 39 | + ExpiryDate = expiryDate; |
| 40 | + ModificationDate = modificationDate; |
| 41 | + |
| 42 | + Cookies = cookies; |
| 43 | + Headers = headers; |
| 44 | + } |
| 45 | + |
| 46 | + #endregion |
| 47 | + |
| 48 | + #region Functionality |
| 49 | + |
| 50 | + public void Apply(IResponseBuilder builder) |
| 51 | + { |
| 52 | + if (Status != null) |
| 53 | + { |
| 54 | + builder.Status(Status.Value.RawStatus, Status.Value.Phrase); |
| 55 | + } |
| 56 | + |
| 57 | + if (null != ContentType) |
| 58 | + { |
| 59 | + builder.Type(ContentType); |
| 60 | + } |
| 61 | + |
| 62 | + if (Cookies?.Count > 0) |
| 63 | + { |
| 64 | + foreach (var cookie in Cookies) |
| 65 | + { |
| 66 | + builder.Cookie(cookie); |
| 67 | + } |
| 68 | + } |
| 69 | + |
| 70 | + if (Encoding != null) |
| 71 | + { |
| 72 | + builder.Encoding(Encoding); |
| 73 | + } |
| 74 | + |
| 75 | + if (ExpiryDate != null) |
| 76 | + { |
| 77 | + builder.Expires(ExpiryDate.Value); |
| 78 | + } |
| 79 | + |
| 80 | + if (ModificationDate != null) |
| 81 | + { |
| 82 | + builder.Modified(ModificationDate.Value); |
| 83 | + } |
| 84 | + |
| 85 | + if (Headers?.Count > 0) |
| 86 | + { |
| 87 | + foreach (var header in Headers) |
| 88 | + { |
| 89 | + builder.Header(header.Key, header.Value); |
| 90 | + } |
| 91 | + } |
| 92 | + } |
| 93 | + |
| 94 | + #endregion |
| 95 | + |
| 96 | + } |
| 97 | + |
| 98 | +} |
0 commit comments