Re: [PR] kie-issues#2252: Extract the Git HTTP server from the `kie-sandbox-accelerator-quarkus` package to a new package to allow its reuse for new Accelerators [incubator-kie-tools]
thiagoelg merged PR #3450: URL: https://github.com/apache/incubator-kie-tools/pull/3450 -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] - To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
Re: [PR] kie-issues#2252: Extract the Git HTTP server from the `kie-sandbox-accelerator-quarkus` package to a new package to allow its reuse for new Accelerators [incubator-kie-tools]
thiagoelg commented on PR #3450: URL: https://github.com/apache/incubator-kie-tools/pull/3450#issuecomment-3928422937 Had to close and reopen because GitHub was not showing the latest commits. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] - To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
Re: [PR] kie-issues#2252: Extract the Git HTTP server from the `kie-sandbox-accelerator-quarkus` package to a new package to allow its reuse for new Accelerators [incubator-kie-tools]
thiagoelg closed pull request #3450: kie-issues#2252: Extract the Git HTTP server from the `kie-sandbox-accelerator-quarkus` package to a new package to allow its reuse for new Accelerators URL: https://github.com/apache/incubator-kie-tools/pull/3450 -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] - To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
Re: [PR] kie-issues#2252: Extract the Git HTTP server from the `kie-sandbox-accelerator-quarkus` package to a new package to allow its reuse for new Accelerators [incubator-kie-tools]
thiagoelg commented on code in PR #3450:
URL:
https://github.com/apache/incubator-kie-tools/pull/3450#discussion_r2822554555
##
packages/accelerator-git-http-server/src/server.ts:
##
@@ -0,0 +1,193 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import * as http from "http";
+import * as path from "path";
+import * as fs from "fs";
+import { spawn } from "child_process";
+import serveStatic from "serve-static";
+import finalhandler from "finalhandler";
+
+export interface GitHttpServerConfig {
+ port: number;
+ contentRoot: string;
+ logPrefix?: string;
+}
+
+const gitHttpBackendVariableNames = [
+ "QUERY_STRING",
+ "REMOTE_USER",
+ "CONTENT_LENGTH",
+ "HTTP_CONTENT_ENCODING",
+ "REMOTE_USER",
+ "REMOTE_ADDR",
+ "GIT_COMMITTER_NAME",
+ "GIT_COMMITTER_EMAIL",
+ "CONTENT_TYPE",
+ "PATH_INFO",
+ "GIT_PROJECT_ROOT",
+ "PATH_TRANSLATED",
+ "SERVER_PROTOCOL",
+ "REQUEST_METHOD",
+ "GIT_HTTP_EXPORT_ALL",
+ "GIT_HTTP_MAX_REQUEST_BUFFER",
+];
+
+interface BufferState {
+ header: Buffer[];
+ body: Buffer[];
+ completedHeader: boolean;
+}
+
+/**
+ * Creates and starts a Git HTTP server
+ * @param options Server configuration options
+ * @returns HTTP server instance
+ */
+export function startGitHttpServer(options: GitHttpServerConfig): http.Server {
+ const { port, contentRoot, logPrefix = "git-repo-http-dev-server" } =
options;
+
+ const log = (message: string) => console.log(`[${logPrefix}] ${message}`);
+
+ if (!fs.existsSync(contentRoot)) {
+throw new Error(`Can't serve content from non-existent directory
'${contentRoot}'.`);
+ }
+
+ const serveAsStaticContent = serveStatic(contentRoot);
+
+ const server = http.createServer((req, res) => {
+// bare git repos
+if (req.url?.split("/")[1].endsWith(".git")) {
Review Comment:
There's no need to support deeply nested .git repos.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
-
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
Re: [PR] kie-issues#2252: Extract the Git HTTP server from the `kie-sandbox-accelerator-quarkus` package to a new package to allow its reuse for new Accelerators [incubator-kie-tools]
yesamer commented on code in PR #3450:
URL:
https://github.com/apache/incubator-kie-tools/pull/3450#discussion_r2821054979
##
packages/accelerator-git-http-server/src/server.ts:
##
@@ -0,0 +1,193 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import * as http from "http";
+import * as path from "path";
+import * as fs from "fs";
+import { spawn } from "child_process";
+import serveStatic from "serve-static";
+import finalhandler from "finalhandler";
+
+export interface GitHttpServerConfig {
+ port: number;
+ contentRoot: string;
+ logPrefix?: string;
+}
+
+const gitHttpBackendVariableNames = [
+ "QUERY_STRING",
+ "REMOTE_USER",
+ "CONTENT_LENGTH",
+ "HTTP_CONTENT_ENCODING",
+ "REMOTE_USER",
+ "REMOTE_ADDR",
+ "GIT_COMMITTER_NAME",
+ "GIT_COMMITTER_EMAIL",
+ "CONTENT_TYPE",
+ "PATH_INFO",
+ "GIT_PROJECT_ROOT",
+ "PATH_TRANSLATED",
+ "SERVER_PROTOCOL",
+ "REQUEST_METHOD",
+ "GIT_HTTP_EXPORT_ALL",
+ "GIT_HTTP_MAX_REQUEST_BUFFER",
+];
Review Comment:
@thiagoelg ^^
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
-
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
Re: [PR] kie-issues#2252: Extract the Git HTTP server from the `kie-sandbox-accelerator-quarkus` package to a new package to allow its reuse for new Accelerators [incubator-kie-tools]
Copilot commented on code in PR #3450:
URL:
https://github.com/apache/incubator-kie-tools/pull/3450#discussion_r2820961479
##
packages/accelerator-git-http-server/tests/integration.test.ts:
##
@@ -0,0 +1,197 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import * as http from "http";
+import * as fs from "fs";
+import * as path from "path";
+import { startGitHttpServer } from "../src/server";
+
+async function startServerAndWait(config: {
+ port: number;
+ contentRoot: string;
+ logPrefix?: string;
+}): Promise {
+ const server = startGitHttpServer(config);
+ return new Promise((resolve) => {
+server.on("listening", () => resolve(server));
+ });
+}
+
+describe("Integration Tests", () => {
+ let server: http.Server;
+ let testPort = 9881;
+ const testContentRoot = path.join(__dirname,
"../dist-tests/test-integration-content");
+
+ beforeEach(() => {
+if (!fs.existsSync(testContentRoot)) {
+ fs.mkdirSync(testContentRoot, { recursive: true });
+}
+ });
+
+ afterEach(async () => {
+if (server) {
+ await new Promise((resolve, reject) => {
+server.close((err) => {
+ if (err) reject(err);
+ else resolve();
+});
+ });
+ server = null as any;
+}
+
+if (fs.existsSync(testContentRoot)) {
+ fs.rmSync(testContentRoot, { recursive: true, force: true });
+}
+
+testPort++;
+ });
+
+ describe("Mixed content serving", () => {
+it("should serve both Git repos and static content simultaneously", async
() => {
+ // Setup
+ fs.writeFileSync(path.join(testContentRoot, "index.html"),
"Test");
+ fs.mkdirSync(path.join(testContentRoot, "test.git"), { recursive: true
});
+
+ server = await startServerAndWait({
+port: testPort,
+contentRoot: testContentRoot,
+ });
+
+ // Test static content and Git repo endpoint concurrently
+ const [staticRes, gitRes] = await Promise.all([
+fetch(`http://localhost:${testPort}/index.html`),
+fetch(`http://localhost:${testPort}/test.git/info/refs`),
+ ]);
+
+ expect(staticRes.status).toBe(200);
+ expect(gitRes.status).toBeDefined();
+});
+
+it("should handle multiple concurrent requests", async () => {
+ const files = ["file1.txt", "file2.txt", "file3.txt", "file4.txt"];
+ files.forEach((file) => {
+fs.writeFileSync(path.join(testContentRoot, file), `Content of
${file}`);
+ });
+
+ server = await startServerAndWait({
+port: testPort,
+contentRoot: testContentRoot,
+ });
+
+ const responses = await Promise.all(files.map((file) =>
fetch(`http://localhost:${testPort}/${file}`)));
+
+ responses.forEach((res) => {
+expect(res.status).toBe(200);
+ });
+});
+ });
+
+ describe("Content type handling", () => {
+it("should serve HTML files with correct content type", async () => {
+ fs.writeFileSync(path.join(testContentRoot, "test.html"),
"");
+
+ server = await startServerAndWait({
+port: testPort,
+contentRoot: testContentRoot,
+ });
+
+ const res = await fetch(`http://localhost:${testPort}/test.html`);
+ expect(res.headers.get("content-type")).toContain("text/html");
+});
+
+it("should serve JSON files with correct content type", async () => {
+ fs.writeFileSync(path.join(testContentRoot, "data.json"), '{"key":
"value"}');
+
+ server = await startServerAndWait({
+port: testPort,
+contentRoot: testContentRoot,
+ });
+
+ const res = await fetch(`http://localhost:${testPort}/data.json`);
+ expect(res.headers.get("content-type")).toContain("application/json");
+});
+
+it("should serve CSS files with correct content type", async () => {
+ fs.writeFileSync(path.join(testContentRoot, "styles.css"), "body {
margin: 0; }");
+
+ server = await startServerAndWait({
+port: testPort,
+contentRoot: testContentRoot,
+ });
+
+ const res = await fetch(`http://localhost:${testPort}/styles.css`);
+ expect(res.headers.get("content-type")).toContain("text/css");
+});
+ });
+
+ describe("Directory structure", ()
