-
Notifications
You must be signed in to change notification settings - Fork 97
Expand file tree
/
Copy pathResourceHints.cs
More file actions
298 lines (267 loc) · 11.7 KB
/
Copy pathResourceHints.cs
File metadata and controls
298 lines (267 loc) · 11.7 KB
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
namespace net.openstack.Core.Domain
{
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using JSIStudios.SimpleRESTServices.Client;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using Newtonsoft.Json.Linq;
using ContentType = System.Net.Mime.ContentType;
/// <summary>
/// This class models the Resource Hints of the home document described by
/// <strong>Home Documents for HTTP APIs</strong>.
/// </summary>
/// <remarks>
/// Resource hints allow clients to find relevant information about
/// interacting with a resource beforehand, as a means of optimizing
/// communications, as well as advertising available behaviors (e.g., to
/// aid in laying out a user interface for consuming the API).
///
/// <para>Hints are just that - they are not a "contract", and are to only
/// be taken as advisory. The runtime behavior of the resource always
/// overrides hinted information.</para>
///
/// <para>For example, a resource might hint that the PUT method is allowed
/// on all "widget" resources. This means that generally, the user has the
/// ability to PUT to a particular resource, but a specific resource
/// could reject a PUT based upon access control or other considerations.
/// More fine-grained information might be gathered by interacting with
/// the resource (e.g., via a GET), or by another resource "containing"
/// it (such as a "widgets" collection).</para>
///
/// <para>The current specification defines a set of common hints, based
/// upon information that's discoverable by directly interacting with
/// resources. A future draft will explain how to define new hints.</para>
/// </remarks>
/// <seealso href="http://tools.ietf.org/html/draft-nottingham-json-home-03#section-4">Resource Hints (Home Documents for HTTP APIs - draft-nottingham-json-home-03)</seealso>
/// <threadsafety static="true" instance="false"/>
/// <preliminary/>
[JsonObject(MemberSerialization.OptIn)]
public class ResourceHints : ExtensibleJsonObject
{
#pragma warning disable 649 // Field 'fieldName' is never assigned to, and will always have its default value {value}
/// <summary>
/// This is the backing field for the <see cref="Allow"/> property.
/// </summary>
[JsonProperty("allow", DefaultValueHandling = DefaultValueHandling.Ignore, ItemConverterType = typeof(StringEnumConverter))]
private HttpMethod[] _allow;
/// <summary>
/// This is the backing field for the <see cref="Formats"/> property.
/// </summary>
[JsonProperty("formats", DefaultValueHandling = DefaultValueHandling.Ignore)]
private Dictionary<string, JObject> _formats;
/// <summary>
/// This is the backing field for the <see cref="AcceptPatch"/> property.
/// </summary>
[JsonProperty("accept-patch", DefaultValueHandling = DefaultValueHandling.Ignore)]
private string[] _acceptPatch;
/// <summary>
/// This is the backing field for the <see cref="AcceptPost"/> property.
/// </summary>
[JsonProperty("accept-post", DefaultValueHandling = DefaultValueHandling.Ignore)]
private string[] _acceptPost;
/// <summary>
/// This is the backing field for the <see cref="AcceptPut"/> property.
/// </summary>
[JsonProperty("accept-put", DefaultValueHandling = DefaultValueHandling.Ignore)]
private string[] _acceptPut;
/// <summary>
/// This is the backing field for the <see cref="AcceptRanges"/> property.
/// </summary>
[JsonProperty("accept-ranges", DefaultValueHandling = DefaultValueHandling.Ignore)]
private string[] _acceptRanges;
/// <summary>
/// This is the backing field for the <see cref="Prefer"/> property.
/// </summary>
[JsonProperty("prefer", DefaultValueHandling = DefaultValueHandling.Ignore)]
private string[] _prefer;
/// <summary>
/// This is the backing field for the <see cref="Docs"/> property.
/// </summary>
[JsonProperty("docs", DefaultValueHandling = DefaultValueHandling.Ignore)]
private string _docs;
/// <summary>
/// This is the backing field for the <see cref="Preconditions"/> property.
/// </summary>
[JsonProperty("precondition-req", DefaultValueHandling = DefaultValueHandling.Ignore)]
private string[] _preconditionReq;
/// <summary>
/// This is the backing field for the <see cref="AuthenticationRequirements"/> property.
/// </summary>
[JsonProperty("auth-req", DefaultValueHandling = DefaultValueHandling.Ignore)]
private AuthenticationRequirement[] _authReq;
/// <summary>
/// This is the backing field for the <see cref="Status"/> property.
/// </summary>
[JsonProperty("status", DefaultValueHandling = DefaultValueHandling.Ignore)]
private string _status;
#pragma warning restore 649
/// <summary>
/// Gets the HTTP methods that the current client will be able to use to interact
/// with the resource; equivalent to the <strong>Allow</strong> HTTP response
/// header.
/// </summary>
public ReadOnlyCollection<HttpMethod> Allow
{
get
{
if (_allow == null)
return null;
return new ReadOnlyCollection<HttpMethod>(_allow);
}
}
/// <summary>
/// Gets the representation types that the resource produces and consumes, using the
/// GET and PUT methods respectively, subject to the <see cref="Allow"/> hint. The
/// keys of this collections are <see cref="ContentType.MediaType">media types</see>,
/// and the values are objects which have not yet been defined.
/// </summary>
public Dictionary<string, JObject> Formats
{
get
{
return _formats;
}
}
/// <summary>
/// Gets the PATCH request formats accepted by the resource for this client;
/// equivalent to the <strong>Accept-Patch</strong> HTTP response header.
/// </summary>
/// <seealso href="http://tools.ietf.org/html/rfc5789">RFC5789 (PATCH Method for HTTP)</seealso>
public ReadOnlyCollection<string> AcceptPatch
{
get
{
if (_acceptPatch == null)
return null;
return new ReadOnlyCollection<string>(_acceptPatch);
}
}
/// <summary>
/// Gets the POST request formats accepted by the resource for this client.
/// </summary>
public ReadOnlyCollection<string> AcceptPost
{
get
{
if (_acceptPost == null)
return null;
return new ReadOnlyCollection<string>(_acceptPost);
}
}
/// <summary>
/// Gets the PUT request formats accepted by the resource for this client.
/// </summary>
/// <remarks>
/// If this value is <see langword="null"/>, a client may assume that any format indicated by
/// the <see cref="Formats"/> hint is acceptable in a PUT.
/// </remarks>
public ReadOnlyCollection<string> AcceptPut
{
get
{
if (_acceptPut == null)
return null;
return new ReadOnlyCollection<string>(_acceptPut);
}
}
/// <summary>
/// Gets the range-specifiers available to the client for this resource;
/// equivalent to the <strong>Accept-Ranges</strong> HTTP response header.
/// </summary>
/// <remarks>
/// The values are HTTP range specifiers.
/// </remarks>
/// <seealso href="http://tools.ietf.org/html/draft-ietf-httpbis-p5-range-24#section-2.3">Accept-Ranges (Hypertext Transfer Protocol (HTTP/1.1): Range Requests - draft-ietf-httpbis-p5-range-24)</seealso>
public ReadOnlyCollection<string> AcceptRanges
{
get
{
if (_acceptRanges == null)
return null;
return new ReadOnlyCollection<string>(_acceptRanges);
}
}
/// <summary>
/// Gets the preferences supported by the resource. Note that, as per that
/// specification, a preference can be ignored by the server.
/// </summary>
/// <seealso href="http://tools.ietf.org/html/draft-snell-http-prefer-12">Prefer Header for HTTP (draft-snell-http-prefer-12)</seealso>
public ReadOnlyCollection<string> Prefer
{
get
{
if (_prefer == null)
return null;
return new ReadOnlyCollection<string>(_prefer);
}
}
/// <summary>
/// Gets the location for human-readable documentation for the relation type
/// of the resource.
/// </summary>
public Uri Docs
{
get
{
if (_docs == null)
return null;
return new Uri(_docs);
}
}
/// <summary>
/// Gets a collection of preconditions that the resource may require for
/// state-changing requests (e.g., PUT, PATCH) to include a precondition,
/// to avoid conflicts due to concurrent updates.
/// </summary>
/// <remarks>
/// This collection may contain the values <literal>"etag"</literal> and
/// <literal>"last-modified"</literal> indicating the type of precondition
/// expected.
/// </remarks>
/// <seealso href="http://tools.ietf.org/html/draft-ietf-httpbis-p4-conditional-24">Hypertext Transfer Protocol (HTTP/1.1): Conditional Requests (draft-ietf-httpbis-p4-conditional-24)</seealso>
public ReadOnlyCollection<string> Preconditions
{
get
{
if (_preconditionReq == null)
return null;
return new ReadOnlyCollection<string>(_preconditionReq);
}
}
/// <summary>
/// Gets a collection of requirements for authentication using the HTTP Authentication Framework.
/// </summary>
/// <seealso cref="AuthenticationRequirement"/>
/// <seealso href="http://tools.ietf.org/html/draft-ietf-httpbis-p7-auth-24">Hypertext Transfer Protocol (HTTP/1.1): Authentication (draft-ietf-httpbis-p7-auth-24)</seealso>
public ReadOnlyCollection<AuthenticationRequirement> AuthenticationRequirements
{
get
{
if (_authReq == null)
return null;
return new ReadOnlyCollection<AuthenticationRequirement>(_authReq);
}
}
/// <summary>
/// Gets the status of the resource. Possible values for the status are
/// <literal>"deprecated"</literal> and <literal>"gone"</literal>.
/// </summary>
/// <remarks>
/// Some possible values for this property are:
///
/// <list type="bullet">
/// <item><c>deprecated</c>: indicates that use of the resource is not recommended, but it is still available.</item>
/// <item><c>gone</c>: indicates that the resource is no longer available; i.e. it will return a 410 Gone HTTP status code if accessed.</item>
/// </list>
/// </remarks>
public string Status
{
get
{
return _status;
}
}
}
}