|
1 | 1 | /*
|
2 |
| - * Copyright (C) 2015-2022 Thomas Akehurst |
| 2 | + * Copyright (C) 2015-2023 Thomas Akehurst |
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | * you may not use this file except in compliance with the License.
|
|
18 | 18 | import static com.github.tomakehurst.wiremock.common.Exceptions.throwUnchecked;
|
19 | 19 |
|
20 | 20 | import jakarta.servlet.ServletResponse;
|
| 21 | +import jakarta.servlet.http.HttpServletRequest; |
21 | 22 | import jakarta.servlet.http.HttpServletResponse;
|
22 | 23 | import jakarta.servlet.http.HttpServletResponseWrapper;
|
23 |
| -import java.lang.reflect.Method; |
24 | 24 | import java.net.Socket;
|
25 | 25 | import java.nio.channels.SocketChannel;
|
26 |
| -import java.util.HashMap; |
27 |
| -import java.util.Map; |
28 |
| -import org.eclipse.jetty.http.HttpURI; |
29 | 26 | import org.eclipse.jetty.io.ssl.SslConnection;
|
30 | 27 | import org.eclipse.jetty.server.HttpChannel;
|
31 | 28 | import org.eclipse.jetty.server.Request;
|
32 | 29 | import org.eclipse.jetty.server.Response;
|
33 | 30 |
|
34 | 31 | public class JettyUtils {
|
35 | 32 |
|
36 |
| - private static final Map<Class<?>, Method> URI_METHOD_BY_CLASS_CACHE = new HashMap<>(); |
37 | 33 | private static final boolean IS_JETTY;
|
38 | 34 |
|
39 | 35 | static {
|
@@ -83,30 +79,13 @@ public static Socket getTlsSocket(Response response) {
|
83 | 79 | }
|
84 | 80 | }
|
85 | 81 |
|
86 |
| - public static boolean uriIsAbsolute(Request request) { |
87 |
| - HttpURI uri = getHttpUri(request); |
88 |
| - return uri.getScheme() != null; |
89 |
| - } |
90 |
| - |
91 |
| - private static HttpURI getHttpUri(Request request) { |
92 |
| - try { |
93 |
| - return (HttpURI) getURIMethodFromClass(request.getClass()).invoke(request); |
94 |
| - } catch (Exception e) { |
95 |
| - throw new IllegalArgumentException(request + " does not have a getUri or getHttpURI method"); |
| 82 | + public static boolean isBrowserProxyRequest(HttpServletRequest request) { |
| 83 | + if (request instanceof Request) { |
| 84 | + Request jettyRequest = (Request) request; |
| 85 | + return "https".equals(jettyRequest.getHttpURI().getScheme()) |
| 86 | + || "http".equals(jettyRequest.getMetaData().getURI().getScheme()); |
96 | 87 | }
|
97 |
| - } |
98 | 88 |
|
99 |
| - private static Method getURIMethodFromClass(Class<?> requestClass) throws NoSuchMethodException { |
100 |
| - if (URI_METHOD_BY_CLASS_CACHE.containsKey(requestClass)) { |
101 |
| - return URI_METHOD_BY_CLASS_CACHE.get(requestClass); |
102 |
| - } |
103 |
| - Method method; |
104 |
| - try { |
105 |
| - method = requestClass.getDeclaredMethod("getUri"); |
106 |
| - } catch (NoSuchMethodException ignored) { |
107 |
| - method = requestClass.getDeclaredMethod("getHttpURI"); |
108 |
| - } |
109 |
| - URI_METHOD_BY_CLASS_CACHE.put(requestClass, method); |
110 |
| - return method; |
| 89 | + return false; |
111 | 90 | }
|
112 | 91 | }
|
0 commit comments