MCPcopy Create free account
hub / github.com/defold/defold / handle

Method handle

engine/dlib/src/test/http_server/TestHttpServer.java:619–890  ·  view source on GitHub ↗
(String target,
                       Request baseRequest,
                       HttpServletRequest request,
                       HttpServletResponse response)

Source from the content-addressed store, hash-verified

617 }
618
619 public void handle(String target,
620 Request baseRequest,
621 HttpServletRequest request,
622 HttpServletResponse response)
623 throws IOException, ServletException
624 {
625 Matcher addm = m_AddPattern.matcher(target);
626 Matcher arbm = m_ArbPattern.matcher(target);
627 Matcher cachedm = m_CachedPattern.matcher(target);
628 Matcher echom = m_EchoPattern.matcher(target);
629 Matcher closem = m_ClosePattern.matcher(target);
630 Matcher sleepm = m_SleepPattern.matcher(target);
631
632 // for HTTP proxy connections using CONNECT method
633 // this toggles the server to proxy connect mode by
634 // responding with a 200 OK with no content
635 if (request.getMethod().equals("CONNECT")) {
636 boolean ok = (proxyConnectMode == false) && target.equals("/");
637 response.setStatus(ok ? HttpServletResponse.SC_OK : HttpServletResponse.SC_BAD_REQUEST);
638 baseRequest.setHandled(true);
639 proxyConnectMode = true;
640 return;
641 }
642
643 if (target.equals("/proxy/to/www.google.com")) {
644 // only accept a request to this target if we are in proxy connect mode
645 // the host header is www.google.com and the request method is a GET
646 String host = request.getHeader("Host");
647 boolean ok = (proxyConnectMode == true)
648 && "www.google.com".equals(host)
649 && request.getMethod().equals("GET");
650 response.setStatus(ok ? HttpServletResponse.SC_OK : HttpServletResponse.SC_BAD_REQUEST);
651 baseRequest.setHandled(true);
652 proxyConnectMode = false;
653 return;
654 }
655 else if (proxyConnectMode) {
656 // requesting some other target while in proxy connect mode
657 // should fail
658 response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
659 baseRequest.setHandled(true);
660 proxyConnectMode = false;
661 return;
662 }
663
664 if (target.equals("/"))
665 {
666 response.getWriter().print("TestHttpServer running!");
667 response.setStatus(HttpServletResponse.SC_OK);
668 baseRequest.setHandled(true);
669 }
670 else if (target.equals("/tls-info"))
671 {
672 Object sslSession = request.getAttribute(SSL_SESSION_ATTRIBUTE);
673 if (sslSession instanceof SSLSession)
674 {
675 response.getWriter().print(((SSLSession)sslSession).getProtocol());
676 response.setStatus(HttpServletResponse.SC_OK);

Callers

nothing calls this directly

Calls 15

calculateSHA1Method · 0.95
parseRangesMethod · 0.95
sendFileMethod · 0.95
existsMethod · 0.95
getHeaderMethod · 0.80
decodeMethod · 0.80
appendMethod · 0.80
valueOfMethod · 0.80
parseIntMethod · 0.80
intValueMethod · 0.80
formatMethod · 0.65
getPathMethod · 0.65

Tested by

no test coverage detected