make endpoints more resilient to missing accept header
This commit is contained in:
parent
4b9f734687
commit
5454d176dd
1 changed files with 33 additions and 21 deletions
|
@ -39,8 +39,12 @@ namespace BirdsiteLive.Controllers
|
|||
[Route("/users")]
|
||||
public IActionResult Index()
|
||||
{
|
||||
var r = Request.Headers["Accept"].First();
|
||||
var acceptHeaders = Request.Headers["Accept"];
|
||||
if (acceptHeaders.Any())
|
||||
{
|
||||
var r = acceptHeaders.First();
|
||||
if (r.Contains("application/activity+json")) return NotFound();
|
||||
}
|
||||
return View("UserNotFound");
|
||||
}
|
||||
|
||||
|
@ -51,7 +55,10 @@ namespace BirdsiteLive.Controllers
|
|||
id = id.Trim(new[] { ' ', '@' }).ToLowerInvariant();
|
||||
var user = _twitterService.GetUser(id);
|
||||
|
||||
var r = Request.Headers["Accept"].First();
|
||||
var acceptHeaders = Request.Headers["Accept"];
|
||||
if (acceptHeaders.Any())
|
||||
{
|
||||
var r = acceptHeaders.First();
|
||||
if (r.Contains("application/activity+json"))
|
||||
{
|
||||
if (user == null) return NotFound();
|
||||
|
@ -59,6 +66,7 @@ namespace BirdsiteLive.Controllers
|
|||
var jsonApUser = JsonConvert.SerializeObject(apUser);
|
||||
return Content(jsonApUser, "application/activity+json; charset=utf-8");
|
||||
}
|
||||
}
|
||||
|
||||
if (user == null) return View("UserNotFound");
|
||||
|
||||
|
@ -79,7 +87,10 @@ namespace BirdsiteLive.Controllers
|
|||
[Route("/users/{id}/statuses/{statusId}")]
|
||||
public IActionResult Tweet(string id, string statusId)
|
||||
{
|
||||
var r = Request.Headers["Accept"].First();
|
||||
var acceptHeaders = Request.Headers["Accept"];
|
||||
if (acceptHeaders.Any())
|
||||
{
|
||||
var r = acceptHeaders.First();
|
||||
if (r.Contains("application/activity+json"))
|
||||
{
|
||||
if (!long.TryParse(statusId, out var parsedStatusId))
|
||||
|
@ -96,6 +107,7 @@ namespace BirdsiteLive.Controllers
|
|||
var jsonApUser = JsonConvert.SerializeObject(status);
|
||||
return Content(jsonApUser, "application/activity+json; charset=utf-8");
|
||||
}
|
||||
}
|
||||
|
||||
return View("Tweet", statusId);
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue