2using System.Collections.Generic;
3using System.Threading.Tasks;
9 internal class ClientChunkRecord : ChunkRecord
11 internal HttpxClient client;
12 internal HttpxResponseEventArgs e;
13 internal SortedDictionary<int, Chunk> chunks =
null;
15 internal EventHandlerAsync<HttpxResponseDataEventArgs> dataCallback;
16 internal IE2eSymmetricCipher symmetricCipher;
17 internal object state;
18 internal string streamId;
21 internal string endpointReference;
22 internal int nextChunk = 0;
25 internal ClientChunkRecord(HttpxClient Client, HttpxResponseEventArgs e,
HttpResponse Response,
26 EventHandlerAsync<HttpxResponseDataEventArgs> DataCallback,
object State,
string StreamId,
string From,
string To,
bool E2e,
27 string EndpointReference, IE2eSymmetricCipher SymmetricCipher)
32 this.response = Response;
33 this.dataCallback = DataCallback;
35 this.streamId = StreamId;
39 this.endpointReference = EndpointReference;
40 this.symmetricCipher = SymmetricCipher;
43 internal override async Task<bool> ChunkReceived(
int Nr,
bool Last,
byte[] Data)
45 if (Nr == this.nextChunk)
47 if (Data.Length > 0 || Last)
49 if (!await this.dataCallback.Raise(
this.client,
new HttpxResponseDataEventArgs(
null, Data, this.streamId, Last, this.state),
false))
51 await this.client.CancelTransfer(this.e.From,
this.streamId);
62 while (!(this.chunks is
null))
64 if (this.chunks.Count == 0)
68 foreach (Chunk Chunk
in this.chunks.Values)
70 if (Chunk.Nr ==
this.nextChunk)
72 if (!await this.dataCallback.Raise(
this.client,
new HttpxResponseDataEventArgs(
null, Chunk.Data,
this.streamId, Chunk.Last,
this.state),
false))
76 this.chunks.Remove(Chunk.Nr);
93 else if (Nr > this.nextChunk)
95 if (this.chunks is
null)
96 this.chunks =
new SortedDictionary<int, Chunk>();
98 this.chunks[Nr] =
new Chunk(Nr, Last, Data);
104 private async Task Done()
106 if (!(this.response is
null))
119 internal override async Task Fail(
string Message)
121 if (this.response is
null)
124 await this.dataCallback.Raise(this.client,
new HttpxResponseDataEventArgs(
null,
new byte[0], this.streamId,
true, this.state),
false);
129 await this.client.CancelTransfer(this.e.From,
this.streamId);
134 public override async Task DisposeAsync()
136 if (!(this.response is
null))
139 this.response =
null;
142 this.chunks?.Clear();
Static class managing the application event log. Applications and services log events on this static ...
static void Exception(Exception Exception, string Object, string Actor, string EventId, EventLevel Level, string Facility, string Module, params KeyValuePair< string, object >[] Tags)
Logs an exception. Event type will be determined by the severity of the exception.
Represets a response of an HTTP client request.
async Task DisposeAsync()
Closes the connection and disposes of all resources.
async Task SendResponse()
Sends the response back to the client. If the resource is synchronous, there's no need to call this m...
bool HeaderSent
If the header has been sent.
The server encountered an unexpected condition which prevented it from fulfilling the request.