import com.intellij.openapi.Disposable;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.components.ApplicationComponent;
+import com.intellij.util.Url;
+import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
+import java.net.URLConnection;
+
public abstract class BuiltInServerManager extends ApplicationComponent.Adapter {
public static BuiltInServerManager getInstance() {
return ApplicationManager.getApplication().getComponent(BuiltInServerManager.class);
@Nullable
public abstract Disposable getServerDisposable();
+
+ public abstract boolean isOnBuiltInWebServer(@Nullable Url url);
+
+ public abstract void configureRequestToWebServer(@NotNull URLConnection connection);
}
\ No newline at end of file
return DefaultHttpHeaders().set(HttpHeaderNames.SET_COOKIE, ServerCookieEncoder.STRICT.encode(STANDARD_COOKIE) + "; SameSite=strict")
}
- SwingUtilities.invokeAndWait {
- ProjectUtil.focusProjectWindow(null, true)
-
- if (MessageDialogBuilder
- .yesNo("", "Page '" + StringUtil.trimMiddle(url, 50) + "' requested without authorization, " +
- "\nyou can copy URL and open it in browser to trust it.")
- .icon(Messages.getWarningIcon())
- .yesText("Copy authorization URL to clipboard")
- .show() == Messages.YES) {
- CopyPasteManager.getInstance().setContents(StringSelection(url + "?" + TOKEN_PARAM_NAME + "=" + acquireToken()))
+ if (!urlDecoder.path().endsWith("/favicon.ico")) {
+ SwingUtilities.invokeAndWait {
+ ProjectUtil.focusProjectWindow(null, true)
+
+ if (MessageDialogBuilder
+ .yesNo("", "Page '" + StringUtil.trimMiddle(url, 50) + "' requested without authorization, " +
+ "\nyou can copy URL and open it in browser to trust it.")
+ .icon(Messages.getWarningIcon())
+ .yesText("Copy authorization URL to clipboard")
+ .show() == Messages.YES) {
+ CopyPasteManager.getInstance().setContents(StringSelection(url + "?" + TOKEN_PARAM_NAME + "=" + acquireToken()))
+ }
}
}
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.util.Disposer;
import com.intellij.openapi.util.NotNullLazyValue;
+import com.intellij.openapi.util.text.StringUtil;
+import com.intellij.util.Url;
+import com.intellij.util.net.NetUtils;
import io.netty.channel.oio.OioEventLoopGroup;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
+import org.jetbrains.builtInWebServer.BuiltInServerOptions;
+import org.jetbrains.builtInWebServer.BuiltInWebServerKt;
import org.jetbrains.io.BuiltInServer;
import org.jetbrains.io.SubServer;
+import java.net.InetAddress;
+import java.net.URLConnection;
+import java.net.UnknownHostException;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import java.util.concurrent.atomic.AtomicBoolean;
return server;
}
+ @Override
+ public boolean isOnBuiltInWebServer(@Nullable Url url) {
+ return url != null && !StringUtil.isEmpty(url.getAuthority()) && isOnBuiltInWebServerByAuthority(url.getAuthority());
+ }
+
+ @Override
+ public void configureRequestToWebServer(@NotNull URLConnection connection) {
+ connection.setRequestProperty(BuiltInWebServerKt.TOKEN_HEADER_NAME, BuiltInWebServerKt.acquireToken());
+ }
+
private static void bindCustomPorts(@NotNull BuiltInServer server) {
if (ApplicationManager.getApplication().isUnitTestMode()) {
return;
}
}
}
+
+ public static boolean isOnBuiltInWebServerByAuthority(@NotNull String authority) {
+ int portIndex = authority.indexOf(':');
+ if (portIndex < 0 || portIndex == authority.length() - 1) {
+ return false;
+ }
+
+ int port;
+ try {
+ port = Integer.parseInt(authority.substring(portIndex + 1));
+ }
+ catch (NumberFormatException ignored) {
+ return false;
+ }
+
+ if (BuiltInServerOptions.getInstance().builtInServerPort != port && BuiltInServerManager.getInstance().getPort() != port) {
+ return false;
+ }
+
+ String host = authority.substring(0, portIndex);
+ if (NetUtils.isLocalhost(host)) {
+ return true;
+ }
+
+ InetAddress inetAddress;
+ try {
+ inetAddress = InetAddress.getByName(host);
+ }
+ catch (UnknownHostException ignored) {
+ return false;
+ }
+
+ if (inetAddress == null) {
+ return false;
+ }
+ return inetAddress.isLoopbackAddress() || inetAddress.isAnyLocalAddress();
+ }
}
\ No newline at end of file
import com.intellij.util.io.HttpRequests;
import com.intellij.util.net.ssl.CertificateManager;
import org.jetbrains.annotations.NotNull;
+import org.jetbrains.ide.BuiltInServerManager;
import java.io.File;
import java.io.IOException;
.connectTimeout(60 * 1000)
.productNameAsUserAgent()
.hostNameVerifier(CertificateManager.HOSTNAME_VERIFIER)
+ .tuner(connection -> {
+ BuiltInServerManager builtInServerManager = BuiltInServerManager.getInstance();
+ if (builtInServerManager.isOnBuiltInWebServer(url)) {
+ builtInServerManager.configureRequestToWebServer(connection);
+ }
+ })
.connect(new HttpRequests.RequestProcessor<Object>() {
@Override
public Object process(@NotNull HttpRequests.Request request) throws IOException {
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.ui.AppUIUtil;
import com.intellij.util.ArrayUtil;
-import com.intellij.util.Url;
import com.intellij.util.Urls;
-import com.intellij.util.net.NetUtils;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
-import org.jetbrains.builtInWebServer.BuiltInServerOptions;
import org.jetbrains.ide.BuiltInServerManager;
-import java.net.InetAddress;
import java.net.URI;
-import java.net.UnknownHostException;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
public final class BrowserLauncherImpl extends BrowserLauncherAppless {
@Override
public void browse(@NotNull String url, @Nullable WebBrowser browser, @Nullable Project project) {
- if (Registry.is("ide.built.in.web.server.activatable", false)) {
- Url parsedUrl = Urls.parse(url, false);
- if (parsedUrl != null && parsedUrl.getAuthority() != null && isOnBuiltInWebServerByAuthority(parsedUrl.getAuthority())) {
- PropertiesComponent.getInstance().setValue("ide.built.in.web.server.active", true);
- }
+ if (Registry.is("ide.built.in.web.server.activatable", false) &&
+ BuiltInServerManager.getInstance().isOnBuiltInWebServer(Urls.parse(url, false))) {
+ PropertiesComponent.getInstance().setValue("ide.built.in.web.server.active", true);
}
super.browse(url, browser, project);
}
- public static boolean isOnBuiltInWebServerByAuthority(@NotNull String authority) {
- int portIndex = authority.indexOf(':');
- if (portIndex < 0 || portIndex == authority.length() - 1) {
- return false;
- }
-
- int port;
- try {
- port = Integer.parseInt(authority.substring(portIndex + 1));
- }
- catch (NumberFormatException ignored) {
- return false;
- }
-
- if (BuiltInServerOptions.getInstance().builtInServerPort != port && BuiltInServerManager.getInstance().getPort() != port) {
- return false;
- }
-
- String host = authority.substring(0, portIndex);
- if (NetUtils.isLocalhost(host)) {
- return true;
- }
-
- InetAddress inetAddress;
- try {
- inetAddress = InetAddress.getByName(host);
- }
- catch (UnknownHostException ignored) {
- return false;
- }
-
- if (inetAddress == null) {
- return false;
- }
- return inetAddress.isLoopbackAddress() || inetAddress.isAnyLocalAddress();
- }
-
@Override
protected void browseUsingNotSystemDefaultBrowserPolicy(@NotNull URI uri, @NotNull GeneralSettings settings, @Nullable Project project) {
WebBrowserManager browserManager = WebBrowserManager.getInstance();
<orderEntry type="module" module-name="xml-structure-view-impl" exported="" />
<orderEntry type="library" name="Netty" level="project" />
<orderEntry type="module" module-name="xdebugger-api" />
- <orderEntry type="module" module-name="built-in-server" />
+ <orderEntry type="module" module-name="built-in-server-api" />
</component>
<component name="copyright">
<Base>