aboutsummaryrefslogtreecommitdiffstats
path: root/src/slskd/Relay/API/Controllers
diff options
context:
space:
mode:
authorJP Dillingham <jp@dillingham.me>2022-12-31 16:25:49 -0600
committerJP Dillingham <jp@dillingham.me>2022-12-31 16:25:49 -0600
commita9b0a16a9ba7c95044a71cb89b37325011685118 (patch)
tree5b36d1b302adee6db4c56305ddbb3a87dab69ad0 /src/slskd/Relay/API/Controllers
parent614170cb68d52af7b9e627444f3758b1809190c1 (diff)
downloadslskd-a9b0a16a9ba7c95044a71cb89b37325011685118.tar.gz
move auth to headers for all endpoints
Diffstat (limited to 'src/slskd/Relay/API/Controllers')
-rw-r--r--src/slskd/Relay/API/Controllers/RelayController.cs25
1 files changed, 9 insertions, 16 deletions
diff --git a/src/slskd/Relay/API/Controllers/RelayController.cs b/src/slskd/Relay/API/Controllers/RelayController.cs
index ec8fef62..7e7f3e22 100644
--- a/src/slskd/Relay/API/Controllers/RelayController.cs
+++ b/src/slskd/Relay/API/Controllers/RelayController.cs
@@ -152,8 +152,9 @@ namespace slskd.Relay
return new UnsupportedMediaTypeResult();
}
- string agentName = default;
- string credential = default;
+ var agentName = Request.Headers["X-Relay-Agent"].FirstOrDefault();
+ var credential = Request.Headers["X-Relay-Credential"].FirstOrDefault();
+
Stream stream = default;
string filename = default;
@@ -161,17 +162,10 @@ namespace slskd.Relay
{
try
{
+ // note: while the actual HTTP request is the same as the one we use for uploading shares, we handle it
+ // differently so that we can capture the stream 'in flight' and avoid any buffering. resist the urge to
+ // refactor one or the other to make them match!
var reader = new MultipartReader(HeaderUtilities.RemoveQuotes(mediaTypeHeader.Boundary).Value, Request.Body);
-
- // the multipart response contains two sections; the name of the agent, the upload credential, and the file
- var agentNameSection = await reader.ReadNextSectionAsync();
- using var sra = new StreamReader(agentNameSection.Body);
- agentName = sra.ReadToEnd();
-
- var credentialSection = await reader.ReadNextSectionAsync();
- using var src = new StreamReader(credentialSection.Body);
- credential = src.ReadToEnd();
-
var fileSection = await reader.ReadNextSectionAsync();
var contentDisposition = ContentDispositionHeaderValue.Parse(fileSection.ContentDisposition);
filename = contentDisposition.FileName.Value;
@@ -243,15 +237,14 @@ namespace slskd.Relay
return new UnsupportedMediaTypeResult();
}
- string agentName = default;
- string credential = default;
+ var agentName = Request.Headers["X-Relay-Agent"].FirstOrDefault();
+ var credential = Request.Headers["X-Relay-Credential"].FirstOrDefault();
+
IEnumerable<Share> shares;
IFormFile database;
try
{
- agentName = Request.Form["name"].ToString();
- credential = Request.Form["credential"].ToString();
shares = Request.Form["shares"].ToString().FromJson<IEnumerable<Share>>();
database = Request.Form.Files[0];
}