// static http request proccessing logic public async Task <IgniteResponse> proccess(IgniteRequest request) { // get resource name from route String route = request.getRoute(); String[] routePath = route.Split("/"); if (route == "/") { logger.debug("StaticHttpProccessor@proccess | default route, servinc default page {0}", DEFAULT_PATH); route = DEFAULT_PATH; } else if (routePath[routePath.Length - 1].Split(".").Length == 1) { // if last path part don't have extension add default logger.debug("StaticHttpProccessor@proccess | no extension, adding default", DEFAULT_EXTENSION); route = route + DEFAULT_EXTENSION; } // reverse slashes ;) route = route.Replace("/", "\\"); logger.info("StaticHttpProccessor@proccess | route {0}", route); // get configured working directory from configuration file ConfigurationService configService = await ConfigurationService.getInstance(); IgniteConfiguration config = configService.getCoreServerConfig(); //Console.WriteLine("StaticHttpProccessor@proccess | config {0}", config); String staticDataDir = config.getProperty(STATIC_DIR_PROP_NAME); // get file by filename try { var file = await FileSystemService.readFullFile(staticDataDir + route); logger.debug("StatichttpProccessor@proccess | file finded", file); IgniteResponse response = IgniteResponseFactory.getInstance(); response.setBody(file); // set MIME TYPE String MIME = MIMEType.getMIMETypeByExtension(getFileExtensionByRoute(route)); response.getHeaders()[HttpHeaders.ContentLength] = " " + file.Length.ToString(); response.getHeaders()[HttpHeaders.ContentType] = " " + MIME; return(response); } catch (FileNotFoundException e) { logger.warn("StaticHttpProccessor@proccess | no file finded by path {0}, reutning 404", staticDataDir + route); return(IgniteResponseFactory.getInstance(new IgniteResponseStatus(HttpStatus.NOT_FOUND, HttpStatus.NOT_FOUND_MESSAGE))); } }
// core request engine low level validation logic public static IgniteResponseStatus validate(IgniteRequest request) { // not valid version if (!request.getHttpVersion().Equals(validHttpVersion)) { Console.WriteLine("IgniteERquestValidatorService@validate | http version not valid, sending 400"); return(new IgniteResponseStatus(HttpStatus.BAD_REQUEST, HttpStatus.BAD_REQUEST_MESSAGE)); } if (request.getRoute().Equals("")) { logger.warn("IgniteERquestValidatorService@validate | route not valid, sending 400"); return(new IgniteResponseStatus(HttpStatus.BAD_REQUEST, HttpStatus.BAD_REQUEST_MESSAGE)); } if (!request.getMethod().Equals(HttpMethod.GET) && !request.getHeaders().ContainsKey(HttpHeaders.ContentLength)) { logger.warn("IgniteERquestValidatorService@validate | no content length header sending 411"); return(new IgniteResponseStatus(HttpStatus.LENGTH_REQUIRED, HttpStatus.LENGTH_REQUIRED_MESSAGE)); } // not supported method if (HttpMethod.getAvalibleMethods().IndexOf(request.getMethod()) == -1) { logger.warn("IgniteERquestValidatorService@validate | not allowed method, sending 501"); return(new IgniteResponseStatus(HttpStatus.NOT_IMPLEMENTED, HttpStatus.NOT_IMPLEMENTED_MESSAGE)); } Dictionary <String, String> headers = request.getHeaders(); foreach (KeyValuePair <String, String> entry in headers) { if (entry.Key.Equals("") || entry.Value.Equals("")) { logger.warn("IgniteERquestValidatorService@validate | headers not valid, sending 400"); return(new IgniteResponseStatus(HttpStatus.BAD_REQUEST, HttpStatus.BAD_REQUEST_MESSAGE)); } } return(new IgniteResponseStatus(HttpStatus.OK, HttpStatus.OK_MESSAGE)); }