Modifying client generator to allow modifying requests before they are sent.

This commit is contained in:
2024-02-19 08:05:48 -08:00
parent 50861d5381
commit 8747b5fb3e
5 changed files with 114 additions and 16 deletions

View File

@ -1,4 +1,4 @@
//Generated using MontoyaTech.Rest.Net
//Generated using MontoyaTech.Rest.Net - 2/18/2024
public class Client
{
@ -10,6 +10,8 @@ public class Client
public System.Net.Http.HttpClient HttpClient;
public System.Action<System.Net.Http.HttpRequestMessage> RequestHandler;
public TestApi Test;
public AuthApi Auth;
@ -18,7 +20,7 @@ public class Client
public FormApi Form;
public Client(string baseUrl, System.Net.Http.HttpMessageHandler handler = null)
public Client(string baseUrl, System.Net.Http.HttpMessageHandler handler = null, System.Action<System.Net.Http.HttpRequestMessage> requestHandler = null)
{
if (string.IsNullOrWhiteSpace(baseUrl))
throw new System.ArgumentException("baseUrl must not be null or whitespace.");
@ -43,6 +45,8 @@ public class Client
this.MessageHandler = handler;
this.RequestHandler = requestHandler;
this.HttpClient = new System.Net.Http.HttpClient(handler);
this.HttpClient.DefaultRequestHeaders.Add("Accept", "*/*");
@ -73,6 +77,8 @@ public class Client
{
var message = new System.Net.Http.HttpRequestMessage(System.Net.Http.HttpMethod.Get, $"{this.Client.BaseUrl}/status");
this.Client.RequestHandler?.Invoke(message);
var response = this.Client.HttpClient.Send(message, System.Net.Http.HttpCompletionOption.ResponseHeadersRead);
if (response.IsSuccessStatusCode)
@ -94,6 +100,8 @@ public class Client
{
var message = new System.Net.Http.HttpRequestMessage(System.Net.Http.HttpMethod.Post, $"{this.Client.BaseUrl}/add/{a}/{b}");
this.Client.RequestHandler?.Invoke(message);
var response = this.Client.HttpClient.Send(message, System.Net.Http.HttpCompletionOption.ResponseHeadersRead);
if (response.IsSuccessStatusCode)
@ -115,6 +123,8 @@ public class Client
{
var message = new System.Net.Http.HttpRequestMessage(System.Net.Http.HttpMethod.Get, $"{this.Client.BaseUrl}/compress");
this.Client.RequestHandler?.Invoke(message);
var response = this.Client.HttpClient.Send(message, System.Net.Http.HttpCompletionOption.ResponseHeadersRead);
if (response.IsSuccessStatusCode)
@ -136,6 +146,8 @@ public class Client
{
var message = new System.Net.Http.HttpRequestMessage(System.Net.Http.HttpMethod.Get, $"{this.Client.BaseUrl}/file/compress");
this.Client.RequestHandler?.Invoke(message);
var response = this.Client.HttpClient.Send(message, System.Net.Http.HttpCompletionOption.ResponseHeadersRead);
if (response.IsSuccessStatusCode)
@ -167,6 +179,8 @@ public class Client
{
var message = new System.Net.Http.HttpRequestMessage(System.Net.Http.HttpMethod.Get, $"{this.Client.BaseUrl}/auth/{name}");
this.Client.RequestHandler?.Invoke(message);
var response = this.Client.HttpClient.Send(message, System.Net.Http.HttpCompletionOption.ResponseHeadersRead);
if (response.IsSuccessStatusCode)
@ -188,6 +202,8 @@ public class Client
{
var message = new System.Net.Http.HttpRequestMessage(System.Net.Http.HttpMethod.Post, $"{this.Client.BaseUrl}/auth/signup");
this.Client.RequestHandler?.Invoke(message);
if (compress)
{
using (var uncompressedStream = new System.IO.MemoryStream(System.Text.Encoding.UTF8.GetBytes(Newtonsoft.Json.JsonConvert.SerializeObject(request))))
@ -220,6 +236,8 @@ public class Client
{
var message = new System.Net.Http.HttpRequestMessage(System.Net.Http.HttpMethod.Get, $"{this.Client.BaseUrl}/auth/");
this.Client.RequestHandler?.Invoke(message);
var response = this.Client.HttpClient.Send(message, System.Net.Http.HttpCompletionOption.ResponseHeadersRead);
if (response.IsSuccessStatusCode)
@ -241,6 +259,8 @@ public class Client
{
var message = new System.Net.Http.HttpRequestMessage(System.Net.Http.HttpMethod.Get, $"{this.Client.BaseUrl}/auth/dynamic");
this.Client.RequestHandler?.Invoke(message);
var response = this.Client.HttpClient.Send(message, System.Net.Http.HttpCompletionOption.ResponseHeadersRead);
if (response.IsSuccessStatusCode)
@ -262,6 +282,8 @@ public class Client
{
var message = new System.Net.Http.HttpRequestMessage(System.Net.Http.HttpMethod.Get, $"{this.Client.BaseUrl}/auth/role");
this.Client.RequestHandler?.Invoke(message);
var response = this.Client.HttpClient.Send(message, System.Net.Http.HttpCompletionOption.ResponseHeadersRead);
if (response.IsSuccessStatusCode)
@ -293,6 +315,8 @@ public class Client
{
var message = new System.Net.Http.HttpRequestMessage(System.Net.Http.HttpMethod.Post, $"{this.Client.BaseUrl}/upload");
this.Client.RequestHandler?.Invoke(message);
request.Seek(0, System.IO.SeekOrigin.Begin);
message.Content = new System.Net.Http.StreamContent(request);
@ -307,6 +331,8 @@ public class Client
{
var message = new System.Net.Http.HttpRequestMessage(System.Net.Http.HttpMethod.Get, $"{this.Client.BaseUrl}/download");
this.Client.RequestHandler?.Invoke(message);
var response = this.Client.HttpClient.Send(message, System.Net.Http.HttpCompletionOption.ResponseHeadersRead);
if (response.IsSuccessStatusCode)
@ -337,6 +363,8 @@ public class Client
{
var message = new System.Net.Http.HttpRequestMessage(System.Net.Http.HttpMethod.Post, $"{this.Client.BaseUrl}/form");
this.Client.RequestHandler?.Invoke(message);
var response = this.Client.HttpClient.Send(message, System.Net.Http.HttpCompletionOption.ResponseHeadersRead);
if (response.IsSuccessStatusCode)