Skip to content

Release v0.5.0

Latest

Choose a tag to compare

@ZhiShengYuan ZhiShengYuan released this 07 Feb 14:54

GitHub Reverse Proxy v0.5.0

Bug Fixes

πŸ› Fixed 404 and 400 errors for full GitHub URLs with base_path configured

Completely resolved issues where full GitHub URLs with schemes (https://, http://) were failing when used with a base path configuration.

The Problem:
When base_path was configured (e.g., /ghproxy), requests like:

GET /ghproxy/https://github.com/golang/go/archive/refs/tags/go1.26rc3.tar.gz

Were failing with:

  • Initial issue: 404 Not Found (route didn't match)
  • After first fix: Router panic (invalid route pattern)
  • After second fix: Router panic (route conflicts)
  • After third fix: 400 Bad Request (base path not stripped)

The Solution:
Implemented a complete middleware-based approach that:

  1. βœ… Intercepts requests containing :// before routing (avoids route conflicts)
  2. βœ… Strips the base path from the request path using config values
  3. βœ… Temporarily modifies c.Request.URL.Path for the URL handler
  4. βœ… Sets context flags to prevent double base path stripping
  5. βœ… Restores the original path after handling for proper logging/metrics

How It Works:

// Middleware detects full URLs and strips base path
if strings.Contains(path, "://") {
    if strings.HasPrefix(path, "/ghproxy/") {
        path = strings.TrimPrefix(path, "/ghproxy")
        c.Request.URL.Path = path  // Now: /https://github.com/...
    }
    urlHandler.Handle(c)  // Receives: https://github.com/... (after leading slash removed)
}

This now works perfectly:

curl http://your-server:8080/ghproxy/https://github.com/golang/go/archive/refs/tags/go1.26rc3.tar.gz
# βœ… Returns the archive file from GitHub

Features

  • βœ… Full GitHub URL support with proper base path handling
  • βœ… Path-based deployment (deploy on subpaths like /ghproxy)
  • βœ… HTTP/HTTPS/SOCKS5 proxy support
  • βœ… Hybrid memory + disk caching with ARC eviction
  • βœ… IP-based and token-based rate limiting
  • βœ… Token-based and basic authentication
  • βœ… SSRF protection and security headers
  • βœ… Prometheus metrics
  • βœ… SSH proxy for Git operations

Installation

Download the appropriate binary for your platform below.

Linux (AMD64)

wget https://github.com/LZUOSS/gh-proxy/releases/download/v0.5.0/gh-proxy-v0.5.0-linux-amd64.tar.gz
tar -xzf gh-proxy-v0.5.0-linux-amd64.tar.gz
sudo chmod +x gh-proxy-v0.5.0-linux-amd64
sudo mv gh-proxy-v0.5.0-linux-amd64 /usr/local/bin/gh-proxy

macOS (ARM64 - Apple Silicon)

wget https://github.com/LZUOSS/gh-proxy/releases/download/v0.5.0/gh-proxy-v0.5.0-darwin-arm64.tar.gz
tar -xzf gh-proxy-v0.5.0-darwin-arm64.tar.gz
chmod +x gh-proxy-v0.5.0-darwin-arm64
sudo mv gh-proxy-v0.5.0-darwin-arm64 /usr/local/bin/gh-proxy

Windows (AMD64)

Download gh-proxy-v0.5.0-windows-amd64.zip and extract.

Quick Start

# Run with default config
gh-proxy

# Run with custom config
gh-proxy -config /path/to/config.yaml

Configuration Example

To enable full URL support with a base path:

server:
  base_path: "/ghproxy"  # All routes will be prefixed with /ghproxy
  http_port: 8080

Usage Examples

With the above config, all these work:

# Full URL with scheme
curl http://localhost:8080/ghproxy/https://github.com/golang/go/archive/refs/tags/go1.26rc3.tar.gz

# URL without scheme
curl http://localhost:8080/ghproxy/github.com/golang/go/archive/refs/tags/go1.26rc3.tar.gz

# Traditional path-based
curl http://localhost:8080/ghproxy/golang/go/archive/refs/tags/go1.26rc3.tar.gz

Documentation

See README.md for full configuration options.

Checksums

See SHA256SUMS for file checksums.


Full Changelog: v0.4.0...v0.5.0