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