Rewrite IPC from HttpListener to KestrelHttpServer (#898)

* Debug tests

* Update

* Add support for IPCPassword

* Misc

* Misc

* Update

* Misc

* Cut dependencies to bare minimum

* Update

* Update

* Update

* Update

* Add support for websockets

* Cleanup and preparation for merge

* Add missing mapping of / -> index.html

* Add support for custom path + misc

* Misc

* Declare latest compatibility version

* Fix harmless error on /Api/Log websocket disconnect
This commit is contained in:
Łukasz Domeradzki
2018-09-08 00:05:23 +02:00
committed by GitHub
parent 5b667476e4
commit e18c8ffa55
30 changed files with 1550 additions and 1400 deletions

View File

@@ -0,0 +1,55 @@
// _ _ _ ____ _ _____
// / \ _ __ ___ | |__ (_)/ ___| | |_ ___ __ _ _ __ ___ | ___|__ _ _ __ _ __ ___
// / _ \ | '__|/ __|| '_ \ | |\___ \ | __|/ _ \ / _` || '_ ` _ \ | |_ / _` || '__|| '_ ` _ \
// / ___ \ | | | (__ | | | || | ___) || |_| __/| (_| || | | | | || _|| (_| || | | | | | | |
// /_/ \_\|_| \___||_| |_||_||____/ \__|\___| \__,_||_| |_| |_||_| \__,_||_| |_| |_| |_|
//
// Copyright 2015-2018 Łukasz "JustArchi" Domeradzki
// Contact: JustArchi@JustArchi.net
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
using System;
using ArchiSteamFarm.IPC.Responses;
using ArchiSteamFarm.Localization;
using Microsoft.AspNetCore.Mvc;
namespace ArchiSteamFarm.IPC.Controllers.Api {
[ApiController]
[Route("Api/Structure")]
public sealed class StructureController : ControllerBase {
[HttpGet("{structure:required}")]
public ActionResult<GenericResponse<object>> Get(string structure) {
if (string.IsNullOrEmpty(structure)) {
ASF.ArchiLogger.LogNullError(nameof(structure));
return BadRequest(new GenericResponse<object>(false, string.Format(Strings.ErrorIsEmpty, nameof(structure))));
}
Type targetType = Utilities.ParseType(structure);
if (targetType == null) {
return BadRequest(new GenericResponse<object>(false, string.Format(Strings.ErrorIsInvalid, structure)));
}
object obj;
try {
obj = Activator.CreateInstance(targetType, true);
} catch (Exception e) {
return BadRequest(new GenericResponse<object>(false, string.Format(Strings.ErrorParsingObject, nameof(targetType)) + Environment.NewLine + e));
}
return Ok(new GenericResponse<object>(obj));
}
}
}