-
Notifications
You must be signed in to change notification settings - Fork 0
/
ProxyContent.cs
41 lines (35 loc) · 973 Bytes
/
ProxyContent.cs
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
using Microsoft.AspNetCore.Http;
using System.Collections.Generic;
using System.IO;
using System.Net;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Threading.Tasks;
namespace tgMessageReverseProxy
{
internal class ProxyContent : HttpContent
{
private readonly Stream _inner;
private readonly long? _size;
private static void UpdateFromReq(HttpContentHeaders toUpdate, HttpRequest req)
{
foreach ((string h, Microsoft.Extensions.Primitives.StringValues v) in req.Headers)
toUpdate.TryAddWithoutValidation(h, (IEnumerable<string>)v);
}
public ProxyContent(HttpRequest req)
{
_inner = req.Body;
_size = req.ContentLength;
UpdateFromReq(Headers, req);
}
protected override Task SerializeToStreamAsync(Stream stream, TransportContext context)
{
return _inner.CopyToAsync(stream);
}
protected override bool TryComputeLength(out long length)
{
length = _size ?? 0L;
return _size.HasValue;
}
}
}