Beispiel #1
0
        private async Task ProcessPostRequestAsync()
        {
            HttpResponse response;

            try
            {
                response = _restHandler.ProcessPostRequest();
            }
            catch (Exception ex)
            {
                await RequestUtils.WriteInternalServerErrorResponse(_streamSocket, ex);

                return;
            }

            await RequestUtils.WriteResponse(response, _streamSocket);
        }
Beispiel #2
0
        private async Task ProcessGetRequestAsync()
        {
            HttpResponse response;

            try
            {
                var localpath = RequestUtils.ParseLocalPath(_request.Uri.LocalPath);

                switch (localpath)
                {
                case "index.html":
                case "hwandazaautomation":
                case "hwandazaautomation/index.html":
                case "status":
                case "settings":
                case "lights":
                case "control":
                case "music":
                case "gallery":
                case "about":
                case "slideshow":
                    response = await _staticFileHandler.HandleRequest("index.html");

                    break;

                case "hwandazaautomation/status":
                    response = GetHwandazaAutomationStatus();
                    response.Headers.Add("Content-Type", ContentTypeMapper.JSON);
                    break;

                case "hwandazaautomation/songs":
                    response = GetHwandazaAutomationSongList();
                    response.Headers.Add("Content-Type", ContentTypeMapper.JSON);
                    break;

                case "hwandazaautomation/videos":
                    response = GetHwandazaAutomationVideoList();
                    response.Headers.Add("Content-Type", ContentTypeMapper.JSON);
                    break;

                case "hwandazaautomation/pictures":
                    response = GetHwandazaAutomationPictureList();
                    response.Headers.Add("Content-Type", ContentTypeMapper.JSON);
                    break;

                case "hwandazaautomation/cover":
                    response = GetHwandazaAutomationCover();
                    response.Headers.Add("Content-Type", ContentTypeMapper.JSON);
                    break;

                default:
                    response = await StaticFileHandlerAsync(localpath);

                    break;
                }
            }
            catch (Exception ex)
            {
                await RequestUtils.WriteInternalServerErrorResponse(_streamSocket, ex);

                return;
            }

            await RequestUtils.WriteResponse(response, _streamSocket);

            response = null;
        }
Beispiel #3
0
 private async Task ProcessBadRequestAsync()
 {
     await RequestUtils.WriteMethodNotAllowedRequest(_streamSocket);
 }