@Override public Response serve(final IHTTPSession session) { String requestPath = Util.stripPrefix(session.getUri(), "/"); @javax.annotation.Nonnull final File file = new File(root, requestPath); if (session.getMethod() == Method.GET) { Comparator<Map.Entry<CharSequence, Function<IHTTPSession, Response>>> objectComparator = Comparator.comparing(x -> x.getKey().length()); Optional<Function<IHTTPSession, Response>> handler = getHandlers.entrySet().stream() return handler.get().apply(session); } catch (Throwable e) { log.warn("Error requesting " + session.getUri(), e); throw new RuntimeException(e); return NanoHTTPD.newFixedLengthResponse(Response.Status.NOT_FOUND, "text/plain", "Not Found"); } else if (session.getMethod() == Method.POST) { Optional<Function<IHTTPSession, Response>> handler = this.postHandlers.entrySet().stream() .filter(e -> requestPath.startsWith(e.getKey().toString())).findAny() return handler.get().apply(session); } catch (Throwable e) { log.warn("Error requesting " + session.getUri(), e); throw new RuntimeException(e);
@Override public Response serve(final IHTTPSession session) { String requestPath = Util.stripPrefix(session.getUri(), "/"); @javax.annotation.Nonnull final File file = new File(root, requestPath); if (session.getMethod() == Method.GET) { Comparator<Map.Entry<CharSequence, Function<IHTTPSession, Response>>> objectComparator = Comparator.comparing(x -> x.getKey().length()); Optional<Function<IHTTPSession, Response>> handler = getHandlers.entrySet().stream() return handler.get().apply(session); } catch (Throwable e) { log.warn("Error requesting " + session.getUri(), e); throw new RuntimeException(e); return NanoHTTPD.newFixedLengthResponse(Response.Status.NOT_FOUND, "text/plain", "Not Found"); } else if (session.getMethod() == Method.POST) { Optional<Function<IHTTPSession, Response>> handler = this.postHandlers.entrySet().stream() .filter(e -> requestPath.startsWith(e.getKey().toString())).findAny() return handler.get().apply(session); } catch (Throwable e) { log.warn("Error requesting " + session.getUri(), e); throw new RuntimeException(e);
@Override public Response serve(final IHTTPSession session) { String requestPath = session.getUri(); while (requestPath.startsWith("/")) { requestPath = requestPath.substring(1); } if (null != primaryFile && requestPath.equals(primaryFile.getName())) { try { @javax.annotation.Nonnull final Response response = NanoHTTPD.newChunkedResponse(Response.Status.OK, mimeType, new BufferedInputStream(dataReciever.newInputStream())); response.setGzipEncoding(false); return response; } catch (@javax.annotation.Nonnull final IOException e) { throw new RuntimeException(e); } } else { return super.serve(session); } }
@Override public Response serve(final IHTTPSession session) { String requestPath = session.getUri(); while (requestPath.startsWith("/")) { requestPath = requestPath.substring(1); } if (null != primaryFile && requestPath.equals(primaryFile.getName())) { try { @javax.annotation.Nonnull final Response response = NanoHTTPD.newChunkedResponse(Response.Status.OK, mimeType, new BufferedInputStream(dataReciever.newInputStream())); response.setGzipEncoding(false); return response; } catch (@javax.annotation.Nonnull final IOException e) { throw new RuntimeException(e); } } else { return super.serve(session); } }
public Response serve(IHTTPSession session) { Map<String, String> files = new HashMap<String, String>(); Method method = session.getMethod(); if (Method.PUT.equals(method) || Method.POST.equals(method)) { try { session.parseBody(files); } catch (IOException ioe) { return newFixedLengthResponse(Response.Status.INTERNAL_ERROR, NanoHTTPD.MIME_PLAINTEXT, "SERVER INTERNAL ERROR: IOException: " + ioe.getMessage()); } catch (ResponseException re) { return newFixedLengthResponse(re.getStatus(), NanoHTTPD.MIME_PLAINTEXT, re.getMessage()); } } Map<String, String> parms = session.getParms(); parms.put(NanoHTTPD.QUERY_STRING_PARAMETER, session.getQueryParameterString()); return serve(session.getUri(), method, session.getHeaders(), parms, files); }
public Response serve(IHTTPSession session) { Map<String, String> files = new HashMap<String, String>(); Method method = session.getMethod(); if (Method.PUT.equals(method) || Method.POST.equals(method)) { try { session.parseBody(files); } catch (IOException ioe) { return newFixedLengthResponse(Response.Status.INTERNAL_ERROR, NanoHTTPD.MIME_PLAINTEXT, "SERVER INTERNAL ERROR: IOException: " + ioe.getMessage()); } catch (ResponseException re) { return newFixedLengthResponse(re.getStatus(), NanoHTTPD.MIME_PLAINTEXT, re.getMessage()); } } Map<String, String> parms = session.getParms(); parms.put(NanoHTTPD.QUERY_STRING_PARAMETER, session.getQueryParameterString()); return serve(session.getUri(), method, session.getHeaders(), parms, files); }