mirror of
https://github.com/hanzoai/runtime.git
synced 2026-10-30 18:23:13 +00:00
- Add main Dockerfile for production builds - Add Dockerfile.runtime for secure code execution - Add Dockerfile.runtime.fixed with improved configuration - Include .dockerignore for build optimization - Add integration documentation and publishing guides - Update API and CLI components for better runtime support - Enhance sandbox and container management features
68 lines
2.0 KiB
Go
68 lines
2.0 KiB
Go
// Copyright 2025 Hanzo Industries Inc.
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
package proxy
|
|
|
|
import (
|
|
"net"
|
|
"net/http"
|
|
"net/http/httputil"
|
|
"net/url"
|
|
"time"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
var proxyTransport = &http.Transport{
|
|
MaxIdleConns: 100,
|
|
MaxIdleConnsPerHost: 100,
|
|
DialContext: (&net.Dialer{
|
|
KeepAlive: 30 * time.Second,
|
|
}).DialContext,
|
|
}
|
|
|
|
// ProxyRequest handles proxying requests to a sandbox's container
|
|
//
|
|
// @Tags toolbox
|
|
// @Summary Proxy requests to the sandbox toolbox
|
|
// @Description Forwards the request to the specified sandbox's container
|
|
// @Param workspaceId path string true "Sandbox ID"
|
|
// @Param projectId path string true "Project ID"
|
|
// @Param path path string true "Path to forward"
|
|
// @Success 200 {object} string "Proxied response"
|
|
// @Failure 400 {object} string "Bad request"
|
|
// @Failure 401 {object} string "Unauthorized"
|
|
// @Failure 404 {object} string "Sandbox container not found"
|
|
// @Failure 409 {object} string "Sandbox container conflict"
|
|
// @Failure 500 {object} string "Internal server error"
|
|
// @Router /workspaces/{workspaceId}/{projectId}/toolbox/{path} [get]
|
|
func NewProxyRequestHandler(getProxyTarget func(*gin.Context) (targetUrl *url.URL, extraHeaders map[string]string, err error)) gin.HandlerFunc {
|
|
return func(ctx *gin.Context) {
|
|
target, extraHeaders, err := getProxyTarget(ctx)
|
|
if err != nil {
|
|
// Error already sent to the context
|
|
return
|
|
}
|
|
|
|
reverseProxy := &httputil.ReverseProxy{
|
|
Director: func(req *http.Request) {
|
|
req.Host = target.Host
|
|
req.URL.Scheme = target.Scheme
|
|
req.URL.Host = target.Host
|
|
req.URL.Path = target.Path
|
|
if target.RawQuery == "" || req.URL.RawQuery == "" {
|
|
req.URL.RawQuery = target.RawQuery + req.URL.RawQuery
|
|
} else {
|
|
req.URL.RawQuery = target.RawQuery + "&" + req.URL.RawQuery
|
|
}
|
|
for key, value := range extraHeaders {
|
|
req.Header.Add(key, value)
|
|
}
|
|
},
|
|
Transport: proxyTransport,
|
|
}
|
|
|
|
reverseProxy.ServeHTTP(ctx.Writer, ctx.Request)
|
|
}
|
|
}
|