| | | 1 | | using System.Collections.Generic; |
| | | 2 | | using System.Linq; |
| | | 3 | | using System.Text; |
| | | 4 | | using WireMock.Util; |
| | | 5 | | using WireMock.Validation; |
| | | 6 | | |
| | | 7 | | namespace WireMock |
| | | 8 | | { |
| | | 9 | | /// <summary> |
| | | 10 | | /// The ResponseMessage. |
| | | 11 | | /// </summary> |
| | | 12 | | public class ResponseMessage |
| | | 13 | | { |
| | | 14 | | /// <summary> |
| | | 15 | | /// Gets the headers. |
| | | 16 | | /// </summary> |
| | 562 | 17 | | public IDictionary<string, WireMockList<string>> Headers { get; set; } = new Dictionary<string, WireMockList<str |
| | | 18 | | |
| | | 19 | | /// <summary> |
| | | 20 | | /// Gets or sets the status code. |
| | | 21 | | /// </summary> |
| | 464 | 22 | | public int StatusCode { get; set; } = 200; |
| | | 23 | | |
| | | 24 | | /// <summary> |
| | | 25 | | /// Gets or sets the body. |
| | | 26 | | /// </summary> |
| | 72 | 27 | | public string BodyOriginal { get; set; } |
| | | 28 | | |
| | | 29 | | /// <summary> |
| | | 30 | | /// Gets or sets the body destination (SameAsSource, String or Bytes). |
| | | 31 | | /// </summary> |
| | 123 | 32 | | public string BodyDestination { get; set; } |
| | | 33 | | |
| | | 34 | | /// <summary> |
| | | 35 | | /// Gets or sets the body as a string. |
| | | 36 | | /// </summary> |
| | 249 | 37 | | public string Body { get; set; } |
| | | 38 | | |
| | | 39 | | /// <summary> |
| | | 40 | | /// Gets or sets the body as a json object. |
| | | 41 | | /// </summary> |
| | 288 | 42 | | public object BodyAsJson { get; set; } |
| | | 43 | | |
| | | 44 | | /// <summary> |
| | | 45 | | /// Gets or sets a value indicating whether child objects to be indented according to the Newtonsoft.Json.JsonTe |
| | | 46 | | /// </summary> |
| | 35 | 47 | | public bool? BodyAsJsonIndented { get; set; } |
| | | 48 | | |
| | | 49 | | /// <summary> |
| | | 50 | | /// Gets or sets the body as bytes. |
| | | 51 | | /// </summary> |
| | 166 | 52 | | public byte[] BodyAsBytes { get; set; } |
| | | 53 | | |
| | | 54 | | /// <summary> |
| | | 55 | | /// Gets or sets the body as a file. |
| | | 56 | | /// </summary> |
| | 108 | 57 | | public string BodyAsFile { get; set; } |
| | | 58 | | |
| | | 59 | | /// <summary> |
| | | 60 | | /// Is the body as file cached? |
| | | 61 | | /// </summary> |
| | 59 | 62 | | public bool? BodyAsFileIsCached { get; set; } |
| | | 63 | | |
| | | 64 | | /// <summary> |
| | | 65 | | /// Gets or sets the body encoding. |
| | | 66 | | /// </summary> |
| | 481 | 67 | | public Encoding BodyEncoding { get; set; } = new UTF8Encoding(false); |
| | | 68 | | |
| | | 69 | | /// <summary> |
| | | 70 | | /// Adds the header. |
| | | 71 | | /// </summary> |
| | | 72 | | /// <param name="name">The name.</param> |
| | | 73 | | /// <param name="value">The value.</param> |
| | | 74 | | public void AddHeader(string name, string value) |
| | 0 | 75 | | { |
| | 0 | 76 | | Headers.Add(name, new WireMockList<string>(value)); |
| | 0 | 77 | | } |
| | | 78 | | |
| | | 79 | | /// <summary> |
| | | 80 | | /// Adds the header. |
| | | 81 | | /// </summary> |
| | | 82 | | /// <param name="name">The name.</param> |
| | | 83 | | /// <param name="values">The values.</param> |
| | | 84 | | public void AddHeader(string name, params string[] values) |
| | 102 | 85 | | { |
| | 102 | 86 | | Check.NotNullOrEmpty(values, nameof(values)); |
| | | 87 | | |
| | 102 | 88 | | var newHeaderValues = Headers.TryGetValue(name, out WireMockList<string> existingValues) |
| | 102 | 89 | | ? values.Union(existingValues).ToArray() |
| | 102 | 90 | | : values; |
| | | 91 | | |
| | 102 | 92 | | Headers[name] = new WireMockList<string>(newHeaderValues); |
| | 102 | 93 | | } |
| | | 94 | | } |
| | | 95 | | } |