File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 44 <AssemblyName >io.github.nonperforming.cafelink</AssemblyName >
55 <Product >RhythmDoctor.CafeLink</Product >
66 <Description >Additional support for rhythm.cafe</Description >
7- <Version >1.0.0 </Version >
7+ <Version >1.0.1 </Version >
88 <LangVersion >latest</LangVersion >
99 <RestoreAdditionalProjectSources >
1010 https://api.nuget.org/v3/index.json;
Original file line number Diff line number Diff line change 1- namespace RhythmDoctor . CafeLink . Server . Handlers ;
1+ using System . Net . Http ;
2+
3+ namespace RhythmDoctor . CafeLink . Server . Handlers ;
24
35internal class ImportHandler : IHandler
46{
57 public string Endpoint => "import" ;
8+ public HttpMethod AcceptedMethod => HttpMethod . Post ;
69
710 public IResponse HandleRequest ( NameValueCollection parameters )
811 {
Original file line number Diff line number Diff line change 1- namespace RhythmDoctor . CafeLink . Server . Handlers ;
1+ using System . Net . Http ;
2+
3+ namespace RhythmDoctor . CafeLink . Server . Handlers ;
24
35internal class PlayHandler : IHandler
46{
57 public string Endpoint => "play" ;
8+ public HttpMethod AcceptedMethod => HttpMethod . Post ;
69
710 public IResponse HandleRequest ( NameValueCollection parameters )
811 {
Original file line number Diff line number Diff line change 1- using System . Text ;
1+ using System . Net . Http ;
2+ using System . Text ;
23
34namespace RhythmDoctor . CafeLink . Server . Handlers ;
45
56internal class StatusHandler : IHandler
67{
78 public string Endpoint => "status" ;
9+ public HttpMethod AcceptedMethod => HttpMethod . Get ;
810
911 public IResponse HandleRequest ( NameValueCollection parameters )
1012 {
Original file line number Diff line number Diff line change 1- namespace RhythmDoctor . CafeLink . Server . Interfaces ;
1+ using System . Net . Http ;
2+
3+ namespace RhythmDoctor . CafeLink . Server . Interfaces ;
24
35internal interface IHandler
46{
57 internal string Endpoint { get ; }
68
9+ HttpMethod AcceptedMethod { get ; }
10+
711 internal IResponse HandleRequest ( NameValueCollection parameters ) ;
812}
Original file line number Diff line number Diff line change 1- namespace RhythmDoctor . CafeLink . Server . Interfaces ;
1+ using System . Net . Http ;
2+
3+ namespace RhythmDoctor . CafeLink . Server . Interfaces ;
24
35public interface IResponse
46{
Original file line number Diff line number Diff line change 1- using System . Text ;
1+ using System . Net . Http ;
2+ using System . Text ;
23
34namespace RhythmDoctor . CafeLink . Server . Responses ;
45
Original file line number Diff line number Diff line change 1- using System . Text ;
1+ using System . Net . Http ;
2+ using System . Text ;
23
34namespace RhythmDoctor . CafeLink . Server ;
45
@@ -98,9 +99,17 @@ private async Task HandleRequest()
9899 }
99100
100101 Plugin . Logger . LogInfo ( $ "[{ nameof ( Server ) } ] Handling '{ endpoint } ' request...") ;
101- response = _handlers . TryGetValue ( endpoint , out IHandler handler )
102- ? handler . HandleRequest ( httpContext . Request . QueryString )
103- : new ErrorResponse ( HttpStatusCode . NotFound , "Unknown endpoint." ) ;
102+ if ( _handlers . TryGetValue ( endpoint , out IHandler handler ) )
103+ {
104+ response =
105+ handler . AcceptedMethod . Method != httpRequest . HttpMethod
106+ ? new ErrorResponse ( HttpStatusCode . MethodNotAllowed , $ "Expected { handler . AcceptedMethod . Method } method.")
107+ : handler . HandleRequest ( httpContext . Request . QueryString ) ;
108+ }
109+ else
110+ {
111+ response = new ErrorResponse ( HttpStatusCode . NotFound , "Unknown endpoint." ) ;
112+ }
104113
105114 SendResponseWithDataAndGetReadyForNextRequest :
106115 IReadOnlyCollection < byte > data = response . Data ;
You can’t perform that action at this time.
0 commit comments