fix(AP): add request header
continuous-integration/drone/push Build is passing Details

Signed-off-by: Sam Therapy <sam@samtherapy.net>
This commit is contained in:
Sam Therapy 2023-02-02 21:07:10 +01:00
parent a29a42c986
commit d22af149b5
Signed by: sam
GPG Key ID: 4D8B07C18F31ACBD
4 changed files with 11 additions and 7 deletions

View File

@ -2,6 +2,7 @@
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Runtime.InteropServices;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;
@ -54,7 +55,7 @@ namespace BirdsiteLive.Domain
var url = $"https://{splittedAcct[1]}/.well-known/webfinger?resource=acct:{splittedAcct[0]}@{splittedAcct[1]}";
var httpClient = _httpClientFactory.CreateClient();
var httpClient = _httpClientFactory.CreateClient("BirdsiteLIVE");
httpClient.DefaultRequestHeaders.Add("Accept", "application/json");
var result = await httpClient.GetAsync(url);
@ -68,7 +69,7 @@ namespace BirdsiteLive.Domain
public async Task<Actor> GetUser(string objectId)
{
var httpClient = _httpClientFactory.CreateClient();
var httpClient = _httpClientFactory.CreateClient("BirdsiteLIVE");
httpClient.DefaultRequestHeaders.Add("Accept", "application/activity+json");
var result = await httpClient.GetAsync(objectId);
@ -156,7 +157,7 @@ namespace BirdsiteLive.Domain
var signature = _cryptoService.SignAndGetSignatureHeader(date, actorUrl, targetHost, digest, usedInbox);
var client = _httpClientFactory.CreateClient();
var client = _httpClientFactory.CreateClient("BirdsiteLIVE");
var httpRequestMessage = new HttpRequestMessage
{
Method = HttpMethod.Post,
@ -178,7 +179,7 @@ namespace BirdsiteLive.Domain
public async Task<WebFingerData> WebFinger(string account)
{
var httpClient = _httpClientFactory.CreateClient();
var httpClient = _httpClientFactory.CreateClient("BirdsiteLIVE");
var result = await httpClient.GetAsync("https://" + account.Split('@')[1] + "/.well-known/webfinger?resource=acct:" + account);
var content = await result.Content.ReadAsStringAsync();

View File

@ -298,7 +298,7 @@ namespace BirdsiteLive.Domain
var url = string.Format(urlPattern, host, id, tweetId);
var client = _httpClientFactory.CreateClient();
var client = _httpClientFactory.CreateClient("BirdsiteLIVE");
var result = await client.PostAsync(url, null);
result.EnsureSuccessStatusCode();
}

View File

@ -85,7 +85,7 @@ namespace BirdsiteLive.Domain
};
//add authorization headers if necessary here
httpRequestMessage.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
var httpClient = _httpClientFactory.CreateClient();
var httpClient = _httpClientFactory.CreateClient("BirdsiteLIVE");
using (var response = await httpClient.SendAsync(httpRequestMessage, cancellationToken))
{
//if (response.IsSuccessStatusCode)

View File

@ -2,6 +2,7 @@ using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Threading.Tasks;
using BirdsiteLive.Common.Settings;
using BirdsiteLive.Common.Structs;
@ -50,7 +51,9 @@ namespace BirdsiteLive
services.AddControllersWithViews();
services.AddHttpClient();
services.AddHttpClient("BirdsiteLIVE", httpClient => {
httpClient.DefaultRequestHeaders.Add("User-Agent", $"BirdsiteLIVE/${Program.VERSION}; +https://{Configuration["Instance:Domain"]}");
});
}
public void ConfigureContainer(ServiceRegistry services)