vs-code-plugin-header-injection-proxy-server-mcp

No description

GitHub Stars

1

User Rating

Not Rated

Favorites

0

Views

7

Forks

0

Issues

0

README
Header Injector Proxy README

This VS Code extension runs a local HTTP proxy server that allows you to route requests based on path prefixes to different backend target URLs. For each target, you can configure it to automatically inject a custom header (like an API Key for authorization) into the outgoing request.

Features
  • Local HTTP Proxy: Runs a simple HTTP proxy server on a configurable local port.
  • Path-Based Routing: Configure multiple target backends. Requests sent to the proxy (e.g., http://localhost:PORT/path/prefix/...) are routed to the corresponding target URL based on the longest matching pathPrefix.
  • Header Injection: For each target, optionally configure an API key (or any value), header name (e.g., Authorization, X-API-Key), and header value prefix (e.g., ApiKey , Bearer ) to be automatically added to requests proxied to that target.
  • UI for Configuration: Manage your proxy targets through a dedicated view in the VS Code Activity Bar. Add, edit, and delete target configurations without manually editing settings.json. (Add/Edit/Delete functionality requires Webviews - implementation might be pending).
  • Status Bar Indicator: Shows the current status of the proxy server (ON/OFF, port) in the VS Code status bar.
  • Automatic Restart: The proxy automatically restarts when relevant configuration settings are changed.

(Consider adding screenshots/GIFs here showing the Targets View and maybe the settings)

Requirements
  • Node.js (Required by the vsce packaging tool and potentially for running the extension host).
Extension Settings

This extension contributes the following settings (manageable via the UI or settings.json):

  • headerInjectorProxy.proxyPort: (Integer) The local port the proxy server will listen on (Default: 8088).
  • headerInjectorProxy.targets: (Array of Objects) Defines the routing and header injection rules. Each object has:
    • pathPrefix: (String, required) URL path prefix on the proxy (e.g., /service1). Must start with /.
    • targetUrl: (String, required) The full target backend URL (e.g., http://api.service1.com).
    • apiKey: (String | null, optional) The API Key (or other value) to inject. Set to null or omit if no injection is needed for this target. (Marked as secret in settings).
    • headerName: (String, optional) The name of the header to inject (Default: Authorization).
    • headerPrefix: (String, optional) A prefix string to add before the apiKey in the header value (Default: ApiKey - includes trailing space).
    • stripPathPrefix: (Boolean, optional) If set to true, the pathPrefix will be removed from the request URL before forwarding it to the targetUrl. For example, if pathPrefix is /api and stripPathPrefix is true, a request to http://localhost:PORT/api/users will be forwarded to targetUrl/users. (Default: false).

Example settings.json configuration:

{
    "headerInjectorProxy.proxyPort": 8088,
    "headerInjectorProxy.targets": [
        {
            "pathPrefix": "/service-alpha",
            "targetUrl": "http://api.alpha.internal:8000",
            "apiKey": "alpha-secret-key-123",
            "headerName": "X-Alpha-Key",
            "headerPrefix": "",
            "stripPathPrefix": false
        },
        {
            "pathPrefix": "/service-beta/v1",
            "targetUrl": "https://api.beta.example.com",
            "apiKey": "beta-secret-key-456",
            "stripPathPrefix": false
        },
        {
            "pathPrefix": "/strip-me",
            "targetUrl": "http://downstream.service/basepath",
            "apiKey": null,
            "stripPathPrefix": true
        }
    ]
}
Known Issues
  • Currently only proxies HTTP requests. Proxying HTTPS requests from the client is not supported. Proxying to HTTPS targets is supported.
  • Websocket proxying is not supported.
  • Path rewriting (e.g., stripping the pathPrefix before forwarding) is not currently implemented; the full request path is forwarded.
  • Add/Edit/Delete functionality in the UI might be pending implementation.
Release Notes
0.0.1
  • Initial release: Basic HTTP proxy, multi-target routing, header injection via settings.json.
  • Added UI View to display configured targets.
  • Added basic Add/Edit/Delete commands (implementation pending).

Enjoy!