mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
cleanup, canonicalRequestPath as CharSequence
This commit is contained in:
@@ -30,7 +30,7 @@ import java.net.UnknownHostException;
|
||||
import static org.jetbrains.io.Responses.sendOptionsResponse;
|
||||
import static org.jetbrains.io.Responses.sendStatus;
|
||||
|
||||
public class BuiltInWebServer extends HttpRequestHandler {
|
||||
public final class BuiltInWebServer extends HttpRequestHandler {
|
||||
private static final Logger LOG = Logger.getInstance(BuiltInWebServer.class);
|
||||
|
||||
@Nullable
|
||||
@@ -67,7 +67,7 @@ public class BuiltInWebServer extends HttpRequestHandler {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean process(@NotNull QueryStringDecoder urlDecoder, @NotNull FullHttpRequest request, @NotNull ChannelHandlerContext context) throws IOException {
|
||||
public boolean process(@NotNull QueryStringDecoder urlDecoder, @NotNull FullHttpRequest request, @NotNull ChannelHandlerContext context) {
|
||||
if (request.method() == HttpMethod.OPTIONS) {
|
||||
sendOptionsResponse("GET, POST, HEAD, OPTIONS", request, context);
|
||||
return true;
|
||||
@@ -123,7 +123,7 @@ public class BuiltInWebServer extends HttpRequestHandler {
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean doProcess(FullHttpRequest request, Channel channel, @Nullable String projectName) {
|
||||
private static boolean doProcess(@NotNull FullHttpRequest request, @NotNull Channel channel, @Nullable String projectName) {
|
||||
final String decodedPath = URLUtil.unescapePercentSequences(UriUtil.trimParameters(request.uri()));
|
||||
int offset;
|
||||
boolean emptyPath;
|
||||
@@ -155,7 +155,6 @@ public class BuiltInWebServer extends HttpRequestHandler {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
final String path = FileUtil.toCanonicalPath(decodedPath.substring(offset + 1), '/');
|
||||
LOG.assertTrue(path != null);
|
||||
PathToFileManager pathToFileManager = PathToFileManager.getInstance(project);
|
||||
@@ -213,7 +212,7 @@ public class BuiltInWebServer extends HttpRequestHandler {
|
||||
|
||||
for (FileHandler fileHandler : FileHandler.EP_NAME.getExtensions()) {
|
||||
try {
|
||||
if (fileHandler.process(result, canonicalRequestPath.toString(), project, request, channel)) {
|
||||
if (fileHandler.process(result, canonicalRequestPath, project, request, channel)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -232,7 +231,7 @@ public class BuiltInWebServer extends HttpRequestHandler {
|
||||
static final class StaticFileHandler extends FileHandler {
|
||||
@Override
|
||||
public boolean process(@NotNull VirtualFile file,
|
||||
@NotNull String canonicalRequestPath,
|
||||
@NotNull CharSequence canonicalRequestPath,
|
||||
@NotNull Project project,
|
||||
@NotNull FullHttpRequest request,
|
||||
@NotNull Channel channel) throws IOException {
|
||||
@@ -252,9 +251,9 @@ public class BuiltInWebServer extends HttpRequestHandler {
|
||||
}
|
||||
}
|
||||
|
||||
private static void redirectToDirectory(HttpRequest request, Channel channel, String path) {
|
||||
private static void redirectToDirectory(@NotNull HttpRequest request, @NotNull Channel channel, @NotNull String path) {
|
||||
FullHttpResponse response = Responses.response(HttpResponseStatus.MOVED_PERMANENTLY);
|
||||
URI url = VfsUtil.toUri("http://" + HttpHeaders.getHost(request) + "/" + path + "/");
|
||||
URI url = VfsUtil.toUri("http://" + HttpHeaders.getHost(request) + '/' + path + '/');
|
||||
LOG.assertTrue(url != null);
|
||||
response.headers().add(HttpHeaders.Names.LOCATION, url.toASCIIString());
|
||||
Responses.send(response, channel, request);
|
||||
|
||||
@@ -13,7 +13,7 @@ public abstract class FileHandler {
|
||||
static final ExtensionPointName<FileHandler> EP_NAME = ExtensionPointName.create("org.jetbrains.webServerFileHandler");
|
||||
|
||||
public abstract boolean process(@NotNull VirtualFile file,
|
||||
@NotNull String canonicalRequestPath,
|
||||
@NotNull CharSequence canonicalRequestPath,
|
||||
@NotNull Project project,
|
||||
@NotNull FullHttpRequest request,
|
||||
@NotNull Channel channel) throws IOException;
|
||||
|
||||
@@ -3,14 +3,16 @@ package org.jetbrains.io.fastCgi;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.Pair;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import org.jetbrains.builtInWebServer.PathToFileManager;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.buffer.ByteBufAllocator;
|
||||
import io.netty.buffer.Unpooled;
|
||||
import io.netty.channel.Channel;
|
||||
import io.netty.handler.codec.http.FullHttpRequest;
|
||||
import io.netty.handler.codec.http.HttpHeaders;
|
||||
import io.netty.util.CharsetUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.builtInWebServer.PathToFileManager;
|
||||
import org.jetbrains.io.Responses;
|
||||
|
||||
import java.net.InetSocketAddress;
|
||||
@@ -28,7 +30,7 @@ public class FastCgiRequest {
|
||||
private final ByteBuf buffer;
|
||||
final int requestId;
|
||||
|
||||
public FastCgiRequest(int requestId, ByteBufAllocator allocator) {
|
||||
public FastCgiRequest(int requestId, @NotNull ByteBufAllocator allocator) {
|
||||
this.requestId = requestId;
|
||||
|
||||
buffer = allocator.buffer();
|
||||
@@ -38,7 +40,7 @@ public class FastCgiRequest {
|
||||
buffer.writeZero(5);
|
||||
}
|
||||
|
||||
public void writeFileHeaders(VirtualFile file, Project project, String canonicalRequestPath) {
|
||||
public void writeFileHeaders(@NotNull VirtualFile file, @NotNull Project project, @NotNull CharSequence canonicalRequestPath) {
|
||||
Pair<VirtualFile, String> root = PathToFileManager.getInstance(project).getRoot(file);
|
||||
FastCgiService.LOG.assertTrue(root != null);
|
||||
addHeader("DOCUMENT_ROOT", root.first.getPath());
|
||||
@@ -46,7 +48,7 @@ public class FastCgiRequest {
|
||||
addHeader("SCRIPT_NAME", canonicalRequestPath);
|
||||
}
|
||||
|
||||
public final void addHeader(@NotNull String key, @Nullable String value) {
|
||||
public final void addHeader(@NotNull String key, @Nullable CharSequence value) {
|
||||
if (value == null) {
|
||||
return;
|
||||
}
|
||||
@@ -75,8 +77,8 @@ public class FastCgiRequest {
|
||||
buffer.writeByte(valLength);
|
||||
}
|
||||
|
||||
buffer.writeBytes(key.getBytes());
|
||||
buffer.writeBytes(value.getBytes());
|
||||
buffer.writeBytes(key.getBytes(CharsetUtil.US_ASCII));
|
||||
buffer.writeBytes(Unpooled.copiedBuffer(value, CharsetUtil.UTF_8));
|
||||
}
|
||||
|
||||
public void writeHeaders(FullHttpRequest request, Channel clientChannel) {
|
||||
|
||||
Reference in New Issue
Block a user