Skip to content

Commit

Permalink
Add headers before sending 304 response
Browse files Browse the repository at this point in the history
  • Loading branch information
cankaratepe23 committed Aug 29, 2024
1 parent 1937e64 commit ebc5d76
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions MedicBot/Controller/AudioController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ public IActionResult Get()
try
{
var lastUpdate = AudioManager.GetLatestUpdateTime();

Response.Headers.LastModified = lastUpdate.ToHttpDate();
Response.Headers.CacheControl = "no-cache";

if (Request.Headers.IfModifiedSince.Count != 0)
{
Expand All @@ -103,9 +106,6 @@ public IActionResult Get()
}
}

Response.Headers.LastModified = lastUpdate.ToHttpDate();
Response.Headers.CacheControl = "no-cache";

return Ok(AudioRepository.All().Select(t => t.ToDto()));
}
catch (Exception e)
Expand All @@ -131,6 +131,9 @@ public IActionResult Get(string audioId, [FromQuery] ulong guildId)
lastUpdate = (DateTimeOffset) track.LastModifiedAt;
}

Response.Headers.LastModified = lastUpdate.ToHttpDate();
Response.Headers.CacheControl = "no-cache";

if (Request.Headers.IfModifiedSince.Count != 0)
{
var ifModifiedSinceStr = Request.Headers.IfModifiedSince[0];
Expand All @@ -144,9 +147,6 @@ public IActionResult Get(string audioId, [FromQuery] ulong guildId)
}
}

Response.Headers.LastModified = lastUpdate.ToHttpDate();
Response.Headers.CacheControl = "no-cache";

var mimeType = MimeTypeMap.GetMimeType(track.Path[track.Path.LastIndexOf('.')..]);
Response.Headers.ContentType = mimeType;

Expand Down Expand Up @@ -179,6 +179,9 @@ public IActionResult Head(string audioId, [FromQuery] ulong guildId)
{
lastUpdate = (DateTimeOffset) track.LastModifiedAt;
}

Response.Headers.LastModified = lastUpdate.ToHttpDate();
Response.Headers.CacheControl = "no-cache";

if (Request.Headers.IfModifiedSince.Count != 0)
{
Expand All @@ -193,9 +196,6 @@ public IActionResult Head(string audioId, [FromQuery] ulong guildId)
}
}

Response.Headers.LastModified = lastUpdate.ToHttpDate();
Response.Headers.CacheControl = "no-cache";

var mimeType = MimeTypeMap.GetMimeType(track.Path[track.Path.LastIndexOf('.')..]);
Response.Headers.ContentType = mimeType;
return Ok();
Expand Down

0 comments on commit ebc5d76

Please sign in to comment.