mirror of
https://github.com/tgstation/tgstation-server.git
synced 2026-08-24 21:46:52 +01:00
161 lines
20 KiB
HTML
161 lines
20 KiB
HTML
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
|
<html xmlns="http://www.w3.org/1999/xhtml" lang="en-US">
|
|
<head>
|
|
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
|
|
<meta http-equiv="X-UA-Compatible" content="IE=11"/>
|
|
<meta name="generator" content="Doxygen 1.9.8"/>
|
|
<meta name="viewport" content="width=device-width, initial-scale=1"/>
|
|
<title>tgstation-server: src/Tgstation.Server.Host/Extensions/ControllerBaseExtensions.cs Source File</title>
|
|
<link href="tabs.css" rel="stylesheet" type="text/css"/>
|
|
<script type="text/javascript" src="jquery.js"></script>
|
|
<script type="text/javascript" src="dynsections.js"></script>
|
|
<link href="search/search.css" rel="stylesheet" type="text/css"/>
|
|
<script type="text/javascript" src="search/searchdata.js"></script>
|
|
<script type="text/javascript" src="search/search.js"></script>
|
|
<link href="doxygen.css" rel="stylesheet" type="text/css" />
|
|
</head>
|
|
<body>
|
|
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
|
|
<div id="titlearea">
|
|
<table cellspacing="0" cellpadding="0">
|
|
<tbody>
|
|
<tr id="projectrow">
|
|
<td id="projectalign">
|
|
<div id="projectname">tgstation-server<span id="projectnumber"> 6.19.3</span>
|
|
</div>
|
|
<div id="projectbrief">The /tg/station 13 server suite</div>
|
|
</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
<!-- end header part -->
|
|
<!-- Generated by Doxygen 1.9.8 -->
|
|
<script type="text/javascript">
|
|
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&dn=expat.txt MIT */
|
|
var searchBox = new SearchBox("searchBox", "search/",'.html');
|
|
/* @license-end */
|
|
</script>
|
|
<script type="text/javascript" src="menudata.js"></script>
|
|
<script type="text/javascript" src="menu.js"></script>
|
|
<script type="text/javascript">
|
|
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&dn=expat.txt MIT */
|
|
$(function() {
|
|
initMenu('',true,false,'search.php','Search');
|
|
$(document).ready(function() { init_search(); });
|
|
});
|
|
/* @license-end */
|
|
</script>
|
|
<div id="main-nav"></div>
|
|
<script type="text/javascript">
|
|
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&dn=expat.txt MIT */
|
|
$(document).ready(function() { init_codefold(0); });
|
|
/* @license-end */
|
|
</script>
|
|
<!-- window showing the filter options -->
|
|
<div id="MSearchSelectWindow"
|
|
onmouseover="return searchBox.OnSearchSelectShow()"
|
|
onmouseout="return searchBox.OnSearchSelectHide()"
|
|
onkeydown="return searchBox.OnSearchSelectKey(event)">
|
|
</div>
|
|
|
|
<!-- iframe showing the search results (closed by default) -->
|
|
<div id="MSearchResultsWindow">
|
|
<div id="MSearchResults">
|
|
<div class="SRPage">
|
|
<div id="SRIndex">
|
|
<div id="SRResults"></div>
|
|
<div class="SRStatus" id="Loading">Loading...</div>
|
|
<div class="SRStatus" id="Searching">Searching...</div>
|
|
<div class="SRStatus" id="NoMatches">No Matches</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div id="nav-path" class="navpath">
|
|
<ul>
|
|
<li class="navelem"><a class="el" href="dir_68267d1309a1af8e8297ef4c3efbcdba.html">src</a></li><li class="navelem"><a class="el" href="dir_34761767c1c3cd212f9d2f80ea0828a8.html">Tgstation.Server.Host</a></li><li class="navelem"><a class="el" href="dir_5ae0a4770cfe9bc511dad7df7deabb23.html">Extensions</a></li> </ul>
|
|
</div>
|
|
</div><!-- top -->
|
|
<div class="header">
|
|
<div class="headertitle"><div class="title">ControllerBaseExtensions.cs</div></div>
|
|
</div><!--header-->
|
|
<div class="contents">
|
|
<a href="_controller_base_extensions_8cs.html">Go to the documentation of this file.</a><div class="fragment"><div class="line"><a id="l00001" name="l00001"></a><span class="lineno"> 1</span><span class="keyword">using </span>System;</div>
|
|
<div class="line"><a id="l00002" name="l00002"></a><span class="lineno"> 2</span><span class="keyword">using </span>System.Net;</div>
|
|
<div class="line"><a id="l00003" name="l00003"></a><span class="lineno"> 3</span><span class="keyword">using </span>System.Net.Mime;</div>
|
|
<div class="line"><a id="l00004" name="l00004"></a><span class="lineno"> 4</span> </div>
|
|
<div class="line"><a id="l00005" name="l00005"></a><span class="lineno"> 5</span><span class="keyword">using </span>Microsoft.AspNetCore.Hosting;</div>
|
|
<div class="line"><a id="l00006" name="l00006"></a><span class="lineno"> 6</span><span class="keyword">using </span>Microsoft.AspNetCore.Mvc;</div>
|
|
<div class="line"><a id="l00007" name="l00007"></a><span class="lineno"> 7</span><span class="keyword">using </span>Microsoft.AspNetCore.StaticFiles;</div>
|
|
<div class="line"><a id="l00008" name="l00008"></a><span class="lineno"> 8</span><span class="keyword">using </span>Microsoft.Extensions.Logging;</div>
|
|
<div class="line"><a id="l00009" name="l00009"></a><span class="lineno"> 9</span><span class="keyword">using </span>Microsoft.Extensions.Primitives;</div>
|
|
<div class="line"><a id="l00010" name="l00010"></a><span class="lineno"> 10</span><span class="keyword">using </span>Microsoft.Net.Http.Headers;</div>
|
|
<div class="line"><a id="l00011" name="l00011"></a><span class="lineno"> 11</span> </div>
|
|
<div class="line"><a id="l00012" name="l00012"></a><span class="lineno"> 12</span><span class="keyword">using </span><a class="code hl_namespace" href="namespace_tgstation_1_1_server_1_1_api_1_1_models.html">Tgstation.Server.Api.Models</a>;</div>
|
|
<div class="line"><a id="l00013" name="l00013"></a><span class="lineno"> 13</span><span class="keyword">using </span><a class="code hl_namespace" href="namespace_tgstation_1_1_server_1_1_api_1_1_models_1_1_response.html">Tgstation.Server.Api.Models.Response</a>;</div>
|
|
<div class="line"><a id="l00014" name="l00014"></a><span class="lineno"> 14</span> </div>
|
|
<div class="line"><a id="l00015" name="l00015"></a><span class="lineno"> 15</span><span class="keyword">namespace </span><a class="code hl_namespace" href="namespace_tgstation_1_1_server_1_1_host_1_1_extensions.html">Tgstation.Server.Host.Extensions</a></div>
|
|
<div class="line"><a id="l00016" name="l00016"></a><span class="lineno"> 16</span>{</div>
|
|
<div class="foldopen" id="foldopen00020" data-start="{" data-end="};">
|
|
<div class="line"><a id="l00020" name="l00020"></a><span class="lineno"><a class="line" href="class_tgstation_1_1_server_1_1_host_1_1_extensions_1_1_controller_base_extensions.html"> 20</a></span> <span class="keyword">static</span> <span class="keyword">class </span><a class="code hl_class" href="class_tgstation_1_1_server_1_1_host_1_1_extensions_1_1_controller_base_extensions.html">ControllerBaseExtensions</a></div>
|
|
<div class="line"><a id="l00021" name="l00021"></a><span class="lineno"> 21</span> {</div>
|
|
<div class="line"><a id="l00028" name="l00028"></a><span class="lineno"><a class="line" href="class_tgstation_1_1_server_1_1_host_1_1_extensions_1_1_controller_base_extensions.html#a0d8d8fd559687a1fb89415868e83ab5e"> 28</a></span> <span class="keyword">public</span> <span class="keyword">static</span> ObjectResult <a class="code hl_function" href="class_tgstation_1_1_server_1_1_host_1_1_extensions_1_1_controller_base_extensions.html#a0d8d8fd559687a1fb89415868e83ab5e">Created</a>(<span class="keyword">this</span> ControllerBase controller, <span class="keywordtype">object</span> payload) => controller.StatusCode(HttpStatusCode.Created, payload);</div>
|
|
<div class="line"><a id="l00029" name="l00029"></a><span class="lineno"> 29</span> </div>
|
|
<div class="line"><a id="l00035" name="l00035"></a><span class="lineno"><a class="line" href="class_tgstation_1_1_server_1_1_host_1_1_extensions_1_1_controller_base_extensions.html#a3f247710918f72172015f8b96ad863b4"> 35</a></span> <span class="keyword">public</span> <span class="keyword">static</span> ObjectResult <a class="code hl_function" href="class_tgstation_1_1_server_1_1_host_1_1_extensions_1_1_controller_base_extensions.html#a3f247710918f72172015f8b96ad863b4">Unauthorized</a>(<span class="keyword">this</span> ControllerBase controller) => controller.StatusCode(HttpStatusCode.Unauthorized, <span class="keyword">null</span>);</div>
|
|
<div class="line"><a id="l00036" name="l00036"></a><span class="lineno"> 36</span> </div>
|
|
<div class="line"><a id="l00042" name="l00042"></a><span class="lineno"><a class="line" href="class_tgstation_1_1_server_1_1_host_1_1_extensions_1_1_controller_base_extensions.html#a914f0cf95624da48a3b4b9c9a7e9b9a3"> 42</a></span> <span class="keyword">public</span> <span class="keyword">static</span> ObjectResult <a class="code hl_function" href="class_tgstation_1_1_server_1_1_host_1_1_extensions_1_1_controller_base_extensions.html#a914f0cf95624da48a3b4b9c9a7e9b9a3">Gone</a>(<span class="keyword">this</span> ControllerBase controller)</div>
|
|
<div class="line"><a id="l00043" name="l00043"></a><span class="lineno"> 43</span> => controller?.StatusCode(HttpStatusCode.Gone, <span class="keyword">new</span> <a class="code hl_class" href="class_tgstation_1_1_server_1_1_api_1_1_models_1_1_response_1_1_error_message_response.html">ErrorMessageResponse</a>(<a class="code hl_enumeration" href="namespace_tgstation_1_1_server_1_1_api_1_1_models.html#a1a6adb59dd51244efabf4e548e7075c8">ErrorCode</a>.ResourceNotPresent)) ?? <span class="keywordflow">throw</span> <span class="keyword">new</span> ArgumentNullException(nameof(controller));</div>
|
|
<div class="line"><a id="l00044" name="l00044"></a><span class="lineno"> 44</span> </div>
|
|
<div class="line"><a id="l00052" name="l00052"></a><span class="lineno"><a class="line" href="class_tgstation_1_1_server_1_1_host_1_1_extensions_1_1_controller_base_extensions.html#a5dea5bfb8313dc112b60fc0936c5b658"> 52</a></span> <span class="keyword">public</span> <span class="keyword">static</span> ObjectResult <a class="code hl_function" href="class_tgstation_1_1_server_1_1_host_1_1_extensions_1_1_controller_base_extensions.html#a5dea5bfb8313dc112b60fc0936c5b658">StatusCode</a>(<span class="keyword">this</span> ControllerBase controller, HttpStatusCode statusCode, <span class="keywordtype">object</span>? errorMessage)</div>
|
|
<div class="line"><a id="l00053" name="l00053"></a><span class="lineno"> 53</span> => controller?.StatusCode((<span class="keywordtype">int</span>)statusCode, errorMessage) ?? <span class="keywordflow">throw</span> <span class="keyword">new</span> ArgumentNullException(nameof(controller));</div>
|
|
<div class="line"><a id="l00054" name="l00054"></a><span class="lineno"> 54</span> </div>
|
|
<div class="foldopen" id="foldopen00063" data-start="{" data-end="}">
|
|
<div class="line"><a id="l00063" name="l00063"></a><span class="lineno"><a class="line" href="class_tgstation_1_1_server_1_1_host_1_1_extensions_1_1_controller_base_extensions.html#a5f8af101180efeb692684bc0eaa347c2"> 63</a></span> <span class="keyword">public</span> <span class="keyword">static</span> VirtualFileResult? <a class="code hl_function" href="class_tgstation_1_1_server_1_1_host_1_1_extensions_1_1_controller_base_extensions.html#a5f8af101180efeb692684bc0eaa347c2">TryServeFile</a>(<span class="keyword">this</span> ControllerBase controller, IWebHostEnvironment hostEnvironment, ILogger logger, <span class="keywordtype">string</span> path)</div>
|
|
<div class="line"><a id="l00064" name="l00064"></a><span class="lineno"> 64</span> {</div>
|
|
<div class="line"><a id="l00065" name="l00065"></a><span class="lineno"> 65</span> ArgumentNullException.ThrowIfNull(controller);</div>
|
|
<div class="line"><a id="l00066" name="l00066"></a><span class="lineno"> 66</span> ArgumentNullException.ThrowIfNull(hostEnvironment);</div>
|
|
<div class="line"><a id="l00067" name="l00067"></a><span class="lineno"> 67</span> ArgumentNullException.ThrowIfNull(logger);</div>
|
|
<div class="line"><a id="l00068" name="l00068"></a><span class="lineno"> 68</span> ArgumentNullException.ThrowIfNull(path);</div>
|
|
<div class="line"><a id="l00069" name="l00069"></a><span class="lineno"> 69</span> </div>
|
|
<div class="line"><a id="l00070" name="l00070"></a><span class="lineno"> 70</span> var fileInfo = hostEnvironment.WebRootFileProvider.GetFileInfo(path);</div>
|
|
<div class="line"><a id="l00071" name="l00071"></a><span class="lineno"> 71</span> <span class="keywordflow">if</span> (fileInfo.Exists)</div>
|
|
<div class="line"><a id="l00072" name="l00072"></a><span class="lineno"> 72</span> {</div>
|
|
<div class="line"><a id="l00073" name="l00073"></a><span class="lineno"> 73</span> logger.LogTrace(<span class="stringliteral">"Serving static file \"{filename}\"..."</span>, path);</div>
|
|
<div class="line"><a id="l00074" name="l00074"></a><span class="lineno"> 74</span> var contentTypeProvider = <span class="keyword">new</span> FileExtensionContentTypeProvider();</div>
|
|
<div class="line"><a id="l00075" name="l00075"></a><span class="lineno"> 75</span> <span class="keywordflow">if</span> (!contentTypeProvider.TryGetContentType(fileInfo.Name, out var contentType))</div>
|
|
<div class="line"><a id="l00076" name="l00076"></a><span class="lineno"> 76</span> contentType = MediaTypeNames.Application.Octet;</div>
|
|
<div class="line"><a id="l00077" name="l00077"></a><span class="lineno"> 77</span> <span class="keywordflow">else</span> <span class="keywordflow">if</span> (contentType == MediaTypeNames.Application.Json)</div>
|
|
<div class="line"><a id="l00078" name="l00078"></a><span class="lineno"> 78</span> controller.Response.Headers.Add(</div>
|
|
<div class="line"><a id="l00079" name="l00079"></a><span class="lineno"> 79</span> HeaderNames.CacheControl,</div>
|
|
<div class="line"><a id="l00080" name="l00080"></a><span class="lineno"> 80</span> <span class="keyword">new</span> StringValues(<span class="keyword">new</span>[] { <span class="stringliteral">"public"</span>, <span class="stringliteral">"max-age=31536000"</span>, <span class="stringliteral">"immutable"</span> }));</div>
|
|
<div class="line"><a id="l00081" name="l00081"></a><span class="lineno"> 81</span> </div>
|
|
<div class="line"><a id="l00082" name="l00082"></a><span class="lineno"> 82</span> <span class="keywordflow">return</span> controller.File(path, contentType);</div>
|
|
<div class="line"><a id="l00083" name="l00083"></a><span class="lineno"> 83</span> }</div>
|
|
<div class="line"><a id="l00084" name="l00084"></a><span class="lineno"> 84</span> </div>
|
|
<div class="line"><a id="l00085" name="l00085"></a><span class="lineno"> 85</span> <span class="keywordflow">return</span> <span class="keyword">null</span>;</div>
|
|
<div class="line"><a id="l00086" name="l00086"></a><span class="lineno"> 86</span> }</div>
|
|
</div>
|
|
<div class="line"><a id="l00087" name="l00087"></a><span class="lineno"> 87</span> }</div>
|
|
</div>
|
|
<div class="line"><a id="l00088" name="l00088"></a><span class="lineno"> 88</span>}</div>
|
|
<div class="ttc" id="aclass_tgstation_1_1_server_1_1_api_1_1_models_1_1_response_1_1_error_message_response_html"><div class="ttname"><a href="class_tgstation_1_1_server_1_1_api_1_1_models_1_1_response_1_1_error_message_response.html">Tgstation.Server.Api.Models.Response.ErrorMessageResponse</a></div><div class="ttdoc">Represents an error message returned by the server.</div><div class="ttdef"><b>Definition</b> <a href="_error_message_response_8cs_source.html#l00011">ErrorMessageResponse.cs:12</a></div></div>
|
|
<div class="ttc" id="aclass_tgstation_1_1_server_1_1_host_1_1_extensions_1_1_controller_base_extensions_html"><div class="ttname"><a href="class_tgstation_1_1_server_1_1_host_1_1_extensions_1_1_controller_base_extensions.html">Tgstation.Server.Host.Extensions.ControllerBaseExtensions</a></div><div class="ttdoc">Extension methods for ControllerBase.</div><div class="ttdef"><b>Definition</b> <a href="_controller_base_extensions_8cs_source.html#l00020">ControllerBaseExtensions.cs:21</a></div></div>
|
|
<div class="ttc" id="aclass_tgstation_1_1_server_1_1_host_1_1_extensions_1_1_controller_base_extensions_html_a0d8d8fd559687a1fb89415868e83ab5e"><div class="ttname"><a href="class_tgstation_1_1_server_1_1_host_1_1_extensions_1_1_controller_base_extensions.html#a0d8d8fd559687a1fb89415868e83ab5e">Tgstation.Server.Host.Extensions.ControllerBaseExtensions.Created</a></div><div class="ttdeci">static ObjectResult Created(this ControllerBase controller, object payload)</div><div class="ttdoc">Generic 201 response with a given payload .</div></div>
|
|
<div class="ttc" id="aclass_tgstation_1_1_server_1_1_host_1_1_extensions_1_1_controller_base_extensions_html_a3f247710918f72172015f8b96ad863b4"><div class="ttname"><a href="class_tgstation_1_1_server_1_1_host_1_1_extensions_1_1_controller_base_extensions.html#a3f247710918f72172015f8b96ad863b4">Tgstation.Server.Host.Extensions.ControllerBaseExtensions.Unauthorized</a></div><div class="ttdeci">static ObjectResult Unauthorized(this ControllerBase controller)</div><div class="ttdoc">Generic 401 response.</div></div>
|
|
<div class="ttc" id="aclass_tgstation_1_1_server_1_1_host_1_1_extensions_1_1_controller_base_extensions_html_a5dea5bfb8313dc112b60fc0936c5b658"><div class="ttname"><a href="class_tgstation_1_1_server_1_1_host_1_1_extensions_1_1_controller_base_extensions.html#a5dea5bfb8313dc112b60fc0936c5b658">Tgstation.Server.Host.Extensions.ControllerBaseExtensions.StatusCode</a></div><div class="ttdeci">static ObjectResult StatusCode(this ControllerBase controller, HttpStatusCode statusCode, object? errorMessage)</div><div class="ttdoc">Strongly type calls to ControllerBase.StatusCode(int, object).</div></div>
|
|
<div class="ttc" id="aclass_tgstation_1_1_server_1_1_host_1_1_extensions_1_1_controller_base_extensions_html_a5f8af101180efeb692684bc0eaa347c2"><div class="ttname"><a href="class_tgstation_1_1_server_1_1_host_1_1_extensions_1_1_controller_base_extensions.html#a5f8af101180efeb692684bc0eaa347c2">Tgstation.Server.Host.Extensions.ControllerBaseExtensions.TryServeFile</a></div><div class="ttdeci">static ? VirtualFileResult TryServeFile(this ControllerBase controller, IWebHostEnvironment hostEnvironment, ILogger logger, string path)</div><div class="ttdoc">Try to serve a given file path .</div><div class="ttdef"><b>Definition</b> <a href="_controller_base_extensions_8cs_source.html#l00063">ControllerBaseExtensions.cs:63</a></div></div>
|
|
<div class="ttc" id="aclass_tgstation_1_1_server_1_1_host_1_1_extensions_1_1_controller_base_extensions_html_a914f0cf95624da48a3b4b9c9a7e9b9a3"><div class="ttname"><a href="class_tgstation_1_1_server_1_1_host_1_1_extensions_1_1_controller_base_extensions.html#a914f0cf95624da48a3b4b9c9a7e9b9a3">Tgstation.Server.Host.Extensions.ControllerBaseExtensions.Gone</a></div><div class="ttdeci">static ObjectResult Gone(this ControllerBase controller)</div><div class="ttdoc">Generic 410 response.</div></div>
|
|
<div class="ttc" id="anamespace_tgstation_1_1_server_1_1_api_1_1_models_1_1_response_html"><div class="ttname"><a href="namespace_tgstation_1_1_server_1_1_api_1_1_models_1_1_response.html">Tgstation.Server.Api.Models.Response</a></div><div class="ttdef"><b>Definition</b> <a href="_administration_response_8cs_source.html#l00005">AdministrationResponse.cs:6</a></div></div>
|
|
<div class="ttc" id="anamespace_tgstation_1_1_server_1_1_api_1_1_models_html"><div class="ttname"><a href="namespace_tgstation_1_1_server_1_1_api_1_1_models.html">Tgstation.Server.Api.Models</a></div><div class="ttdef"><b>Definition</b> <a href="_tgstation_8_server_8_api_2_models_2_chat_channel_8cs_source.html#l00005">ChatChannel.cs:6</a></div></div>
|
|
<div class="ttc" id="anamespace_tgstation_1_1_server_1_1_api_1_1_models_html_a1a6adb59dd51244efabf4e548e7075c8"><div class="ttname"><a href="namespace_tgstation_1_1_server_1_1_api_1_1_models.html#a1a6adb59dd51244efabf4e548e7075c8">Tgstation.Server.Api.Models.ErrorCode</a></div><div class="ttdeci">ErrorCode</div><div class="ttdoc">Types of Response.ErrorMessageResponses that the API may return.</div><div class="ttdef"><b>Definition</b> <a href="_error_code_8cs_source.html#l00011">ErrorCode.cs:12</a></div></div>
|
|
<div class="ttc" id="anamespace_tgstation_1_1_server_1_1_host_1_1_extensions_html"><div class="ttname"><a href="namespace_tgstation_1_1_server_1_1_host_1_1_extensions.html">Tgstation.Server.Host.Extensions</a></div><div class="ttdef"><b>Definition</b> <a href="_application_builder_extensions_8cs_source.html#l00021">ApplicationBuilderExtensions.cs:22</a></div></div>
|
|
</div><!-- fragment --></div><!-- contents -->
|
|
<!-- start footer part -->
|
|
<hr class="footer"/><address class="footer"><small>
|
|
Generated by <a href="https://www.doxygen.org/index.html"><img class="footer" src="doxygen.svg" width="104" height="31" alt="doxygen"/></a> 1.9.8
|
|
</small></address>
|
|
</body>
|
|
</html>
|