| | 1 | | // Copyright (c) Microsoft Corporation. All rights reserved. |
| | 2 | | // Licensed under the MIT License. |
| | 3 | |
|
| | 4 | | using System; |
| | 5 | | using System.Collections.Generic; |
| | 6 | | using System.Diagnostics.CodeAnalysis; |
| | 7 | | using Azure.Core.Pipeline; |
| | 8 | |
|
| | 9 | | namespace Azure.Core |
| | 10 | | { |
| | 11 | | /// <summary> |
| | 12 | | /// Represents an HTTP request. Use <see cref="HttpPipeline.CreateMessage"/> or <see cref="HttpPipeline.CreateReques |
| | 13 | | /// </summary> |
| | 14 | | public abstract class Request : IDisposable |
| | 15 | | { |
| | 16 | | /// <summary> |
| | 17 | | /// Gets or sets and instance of <see cref="RequestUriBuilder"/> used to create the Uri. |
| | 18 | | /// </summary> |
| 0 | 19 | | public virtual RequestUriBuilder Uri { get; set; } = new RequestUriBuilder(); |
| | 20 | |
|
| | 21 | | /// <summary> |
| | 22 | | /// Gets or sets the request HTTP method. |
| | 23 | | /// </summary> |
| 1464 | 24 | | public virtual RequestMethod Method { get; set; } |
| | 25 | |
|
| | 26 | | /// <summary> |
| | 27 | | /// Gets or sets the request content. |
| | 28 | | /// </summary> |
| 160 | 29 | | public virtual RequestContent? Content { get; set; } |
| | 30 | |
|
| | 31 | | /// <summary> |
| | 32 | | /// Adds a header value to the header collection. |
| | 33 | | /// </summary> |
| | 34 | | /// <param name="name">The header name.</param> |
| | 35 | | /// <param name="value">The header value.</param> |
| | 36 | | protected internal abstract void AddHeader(string name, string value); |
| | 37 | |
|
| | 38 | | /// <summary> |
| | 39 | | /// Returns header value if the header is stored in the collection. If the header has multiple values they are g |
| | 40 | | /// </summary> |
| | 41 | | /// <param name="name">The header name.</param> |
| | 42 | | /// <param name="value">The reference to populate with value.</param> |
| | 43 | | /// <returns><c>true</c> if the specified header is stored in the collection, otherwise <c>false</c>.</returns> |
| | 44 | | protected internal abstract bool TryGetHeader(string name, [NotNullWhen(true)] out string? value); |
| | 45 | |
|
| | 46 | | /// <summary> |
| | 47 | | /// Returns header values if the header is stored in the collection. |
| | 48 | | /// </summary> |
| | 49 | | /// <param name="name">The header name.</param> |
| | 50 | | /// <param name="values">The reference to populate with values.</param> |
| | 51 | | /// <returns><c>true</c> if the specified header is stored in the collection, otherwise <c>false</c>.</returns> |
| | 52 | | protected internal abstract bool TryGetHeaderValues(string name, [NotNullWhen(true)] out IEnumerable<string>? va |
| | 53 | |
|
| | 54 | | /// <summary> |
| | 55 | | /// Returns <c>true</c> if the header is stored in the collection. |
| | 56 | | /// </summary> |
| | 57 | | /// <param name="name">The header name.</param> |
| | 58 | | /// <returns><c>true</c> if the specified header is stored in the collection, otherwise <c>false</c>.</returns> |
| | 59 | | protected internal abstract bool ContainsHeader(string name); |
| | 60 | |
|
| | 61 | | /// <summary> |
| | 62 | | /// Sets a header value the header collection. |
| | 63 | | /// </summary> |
| | 64 | | /// <param name="name">The header name.</param> |
| | 65 | | /// <param name="value">The header value.</param> |
| | 66 | | protected internal virtual void SetHeader(string name, string value) |
| | 67 | | { |
| 3874 | 68 | | RemoveHeader(name); |
| 3874 | 69 | | AddHeader(name, value); |
| 3874 | 70 | | } |
| | 71 | | /// <summary> |
| | 72 | | /// Removes the header from the collection. |
| | 73 | | /// </summary> |
| | 74 | | /// <param name="name">The header name.</param> |
| | 75 | | protected internal abstract bool RemoveHeader(string name); |
| | 76 | |
|
| | 77 | | /// <summary> |
| | 78 | | /// Returns an iterator enumerating <see cref="HttpHeader"/> in the request. |
| | 79 | | /// </summary> |
| | 80 | | /// <returns>The <see cref="IEnumerable{T}"/> enumerating <see cref="HttpHeader"/> in the response.</returns> |
| | 81 | | protected internal abstract IEnumerable<HttpHeader> EnumerateHeaders(); |
| | 82 | |
|
| | 83 | | /// <summary> |
| | 84 | | /// Gets or sets the client request id that was sent to the server as <c>x-ms-client-request-id</c> headers. |
| | 85 | | /// </summary> |
| | 86 | | public abstract string ClientRequestId { get; set; } |
| | 87 | |
|
| | 88 | | /// <summary> |
| | 89 | | /// Gets the response HTTP headers. |
| | 90 | | /// </summary> |
| 11312 | 91 | | public RequestHeaders Headers => new RequestHeaders(this); |
| | 92 | |
|
| | 93 | | /// <summary> |
| | 94 | | /// Frees resources held by this <see cref="Response"/> instance. |
| | 95 | | /// </summary> |
| | 96 | | public abstract void Dispose(); |
| | 97 | | } |
| | 98 | | } |