move getheader to abstract (#807)
This commit is contained in:
@@ -2,6 +2,7 @@ using System.Net.Http;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using k8s.Autorest;
|
||||
using k8s.Models;
|
||||
using System.Net.Http.Headers;
|
||||
|
||||
|
||||
@@ -61,12 +62,47 @@ namespace k8s
|
||||
|
||||
public virtual TimeSpan HttpClientTimeout { get; set; } = TimeSpan.FromSeconds(100);
|
||||
|
||||
protected virtual MediaTypeHeaderValue GetHeader(object body)
|
||||
{
|
||||
if (body == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(body));
|
||||
}
|
||||
|
||||
if (body is V1Patch patch)
|
||||
{
|
||||
return GetHeader(patch);
|
||||
}
|
||||
|
||||
return MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
|
||||
}
|
||||
|
||||
private MediaTypeHeaderValue GetHeader(V1Patch body)
|
||||
{
|
||||
if (body == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(body));
|
||||
}
|
||||
|
||||
switch (body.Type)
|
||||
{
|
||||
case V1Patch.PatchType.JsonPatch:
|
||||
return MediaTypeHeaderValue.Parse("application/json-patch+json; charset=utf-8");
|
||||
case V1Patch.PatchType.MergePatch:
|
||||
return MediaTypeHeaderValue.Parse("application/merge-patch+json; charset=utf-8");
|
||||
case V1Patch.PatchType.StrategicMergePatch:
|
||||
return MediaTypeHeaderValue.Parse("application/strategic-merge-patch+json; charset=utf-8");
|
||||
case V1Patch.PatchType.ApplyPatch:
|
||||
return MediaTypeHeaderValue.Parse("application/apply-patch+yaml; charset=utf-8");
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException(nameof(body.Type), "");
|
||||
}
|
||||
}
|
||||
|
||||
protected abstract Task<HttpOperationResponse<T>> CreateResultAsync<T>(HttpRequestMessage httpRequest, HttpResponseMessage httpResponse, bool? watch, CancellationToken cancellationToken);
|
||||
|
||||
protected abstract HttpRequestMessage CreateRequest(string relativeUri, string method, IDictionary<string, IList<string>> customHeaders);
|
||||
|
||||
protected abstract MediaTypeHeaderValue GetHeader(object body);
|
||||
|
||||
protected abstract Task<HttpResponseMessage> SendRequestRaw(string requestContent, HttpRequestMessage httpRequest, CancellationToken cancellationToken);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,46 +0,0 @@
|
||||
using System.Net.Http.Headers;
|
||||
using k8s.Models;
|
||||
|
||||
namespace k8s
|
||||
{
|
||||
public partial class Kubernetes
|
||||
{
|
||||
protected override MediaTypeHeaderValue GetHeader(object body)
|
||||
{
|
||||
if (body == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(body));
|
||||
}
|
||||
|
||||
if (body is V1Patch patch)
|
||||
{
|
||||
return GetHeader(patch);
|
||||
}
|
||||
|
||||
return MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
|
||||
}
|
||||
|
||||
|
||||
private MediaTypeHeaderValue GetHeader(V1Patch body)
|
||||
{
|
||||
if (body == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(body));
|
||||
}
|
||||
|
||||
switch (body.Type)
|
||||
{
|
||||
case V1Patch.PatchType.JsonPatch:
|
||||
return MediaTypeHeaderValue.Parse("application/json-patch+json; charset=utf-8");
|
||||
case V1Patch.PatchType.MergePatch:
|
||||
return MediaTypeHeaderValue.Parse("application/merge-patch+json; charset=utf-8");
|
||||
case V1Patch.PatchType.StrategicMergePatch:
|
||||
return MediaTypeHeaderValue.Parse("application/strategic-merge-patch+json; charset=utf-8");
|
||||
case V1Patch.PatchType.ApplyPatch:
|
||||
return MediaTypeHeaderValue.Parse("application/apply-patch+yaml; charset=utf-8");
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException(nameof(body.Type), "");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user