-
Notifications
You must be signed in to change notification settings - Fork 26
Expand file tree
/
Copy pathProgram.cs
More file actions
49 lines (39 loc) · 1.8 KB
/
Program.cs
File metadata and controls
49 lines (39 loc) · 1.8 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
using Fluxzy;
using Fluxzy.Rules.Actions;
using System.Net;
namespace Samples.No018.TransformResponseBody
{
internal class Program
{
/// <summary>
/// This example shows how to use response body transformation.
/// Response body transformation allows you to modify the response body according to the original request body content.
/// </summary>
/// <param name="args"></param>
static async Task Main(string[] args)
{
// Create a default run settings
var fluxzyStartupSetting = FluxzySetting.CreateLocalRandomPort();
fluxzyStartupSetting.ConfigureRule()
.WhenAny()
.Do(new TransformResponseBodyAction(async (transformContext, bodyReader) => {
var content = await bodyReader.ConsumeAsString();
// Use bodyReader.ConsumeAsStream() to avoid reading the body into memory
// and process it as a stream
return new BodyContent(content.ToUpperInvariant());
}));
// Create a proxy instance
await using var proxy = new Proxy(fluxzyStartupSetting);
var endpoints = proxy.Run();
using var httpClient = new HttpClient(new HttpClientHandler()
{
Proxy = new WebProxy($"http://127.0.0.1:{endpoints.First().Port}"),
UseProxy = true
});
using var response = await httpClient.GetAsync(
"https://www.googleapis.com/books/v1/volumes?q=lords-of-the-rings");
var contentString = await response.Content.ReadAsStringAsync();
Console.ReadKey();
}
}
}