-
Notifications
You must be signed in to change notification settings - Fork 4.9k
/
Copy pathRequest.cs
115 lines (100 loc) · 4.51 KB
/
Request.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Net.Http;
using Azure.Core.Pipeline;
namespace Azure.Core
{
/// <summary>
/// Represents an HTTP request. Use <see cref="HttpPipeline.CreateMessage()"/> or <see cref="HttpPipeline.CreateRequest"/> to create an instance.
/// </summary>
#pragma warning disable AZC0012 // Avoid single word type names
public abstract class Request : IDisposable
#pragma warning restore AZC0012 // Avoid single word type names
{
private RequestUriBuilder? _uri;
/// <summary>
/// Gets or sets and instance of <see cref="RequestUriBuilder"/> used to create the Uri.
/// </summary>
public virtual RequestUriBuilder Uri
{
get
{
return _uri ??= new RequestUriBuilder();
}
set
{
Argument.AssertNotNull(value, nameof(value));
_uri = value;
}
}
/// <summary>
/// Gets or sets the request HTTP method.
/// </summary>
public virtual RequestMethod Method { get; set; }
/// <summary>
/// Gets or sets the request content.
/// </summary>
public virtual RequestContent? Content { get; set; }
/// <summary>
/// Adds a header value to the header collection.
/// </summary>
/// <param name="name">The header name.</param>
/// <param name="value">The header value.</param>
protected internal abstract void AddHeader(string name, string value);
/// <summary>
/// Returns header value if the header is stored in the collection. If the header has multiple values they are going to be joined with a comma.
/// </summary>
/// <param name="name">The header name.</param>
/// <param name="value">The reference to populate with value.</param>
/// <returns><c>true</c> if the specified header is stored in the collection, otherwise <c>false</c>.</returns>
protected internal abstract bool TryGetHeader(string name, [NotNullWhen(true)] out string? value);
/// <summary>
/// Returns header values if the header is stored in the collection.
/// </summary>
/// <param name="name">The header name.</param>
/// <param name="values">The reference to populate with values.</param>
/// <returns><c>true</c> if the specified header is stored in the collection, otherwise <c>false</c>.</returns>
protected internal abstract bool TryGetHeaderValues(string name, [NotNullWhen(true)] out IEnumerable<string>? values);
/// <summary>
/// Returns <c>true</c> if the header is stored in the collection.
/// </summary>
/// <param name="name">The header name.</param>
/// <returns><c>true</c> if the specified header is stored in the collection, otherwise <c>false</c>.</returns>
protected internal abstract bool ContainsHeader(string name);
/// <summary>
/// Sets a header value the header collection.
/// </summary>
/// <param name="name">The header name.</param>
/// <param name="value">The header value.</param>
protected internal virtual void SetHeader(string name, string value)
{
RemoveHeader(name);
AddHeader(name, value);
}
/// <summary>
/// Removes the header from the collection.
/// </summary>
/// <param name="name">The header name.</param>
protected internal abstract bool RemoveHeader(string name);
/// <summary>
/// Returns an iterator enumerating <see cref="HttpHeader"/> in the request.
/// </summary>
/// <returns>The <see cref="IEnumerable{T}"/> enumerating <see cref="HttpHeader"/> in the response.</returns>
protected internal abstract IEnumerable<HttpHeader> EnumerateHeaders();
/// <summary>
/// Gets or sets the client request id that was sent to the server as <c>x-ms-client-request-id</c> headers.
/// </summary>
public abstract string ClientRequestId { get; set; }
/// <summary>
/// Gets the response HTTP headers.
/// </summary>
public RequestHeaders Headers => new(this);
/// <summary>
/// Frees resources held by this <see cref="Response"/> instance.
/// </summary>
public abstract void Dispose();
}
}