Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions core/gateway/internal/mitm/mitm.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"log/slog"
"net"
"net/http"
"os"
"strings"
"sync"
)
Expand Down Expand Up @@ -136,13 +137,22 @@ func (h *Handler) Handle(clientConn net.Conn, initialData []byte, serverName str
// forwardRequest sends the request to the real server over TLS.
func (h *Handler) forwardRequest(req *http.Request, serverName string) (*http.Response, error) {
// Set the host header and request URI
req.URL.Scheme = "https"
req.URL.Host = serverName
req.RequestURI = "" // must be empty for client requests

insecure := os.Getenv("GATEWAY_INSECURE_UPSTREAM") == "true"

if insecure {
// In test mode, forward as HTTP to allow plain-HTTP echo servers.
req.URL.Scheme = "http"
} else {
req.URL.Scheme = "https"
}

transport := &http.Transport{
TLSClientConfig: &tls.Config{
ServerName: serverName,
ServerName: serverName,
InsecureSkipVerify: insecure, //nolint:gosec // test-only
},
// Disable compression so we can stream the raw response bytes
DisableCompression: true,
Expand Down
19 changes: 19 additions & 0 deletions tests/integration/sandbox/compose-override.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Override for integration test: adds a local httpbin echo server
# to eliminate dependency on external httpbin.org.
# Merged with generated .build/docker-compose.yml via -f flag.
services:
echo-httpbin:
image: mccutchen/go-httpbin:v2.16.0
command: ["/bin/go-httpbin", "-port", "80"]
networks:
sandbox:
aliases:
- httpbin.org

# Override gateway to forward upstream as HTTP (echo server is plain HTTP)
sandbox-test-gateway:
environment:
- GATEWAY_INSECURE_UPSTREAM=true
depends_on:
echo-httpbin:
condition: service_started
4 changes: 2 additions & 2 deletions tests/integration/sandbox/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ CLI="${CLI_PATH:-agent-sandbox}"

cleanup() {
echo "--- Cleaning up ---"
"$CLI" -C "$SCRIPT_DIR" compose down -v 2>/dev/null || true
"$CLI" -C "$SCRIPT_DIR" compose -f "$SCRIPT_DIR/compose-override.yml" down -v 2>/dev/null || true
}
trap cleanup EXIT

Expand All @@ -23,7 +23,7 @@ echo ""
echo "--- Building and starting containers ---"
# Export test secrets so compose picks them up
export $(grep -v '^#' "$SCRIPT_DIR/test.env" | xargs)
"$CLI" -C "$SCRIPT_DIR" compose up -d --build --wait --wait-timeout 60
"$CLI" -C "$SCRIPT_DIR" compose -f "$SCRIPT_DIR/compose-override.yml" up -d --build --wait --wait-timeout 60

# Wait for agent entrypoint to complete
sleep 3
Expand Down
Loading