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 matchingpathPrefix
. - 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 tonull
or omit if no injection is needed for this target. (Marked assecret
in settings).headerName
: (String, optional) The name of the header to inject (Default:Authorization
).headerPrefix
: (String, optional) A prefix string to add before theapiKey
in the header value (Default:ApiKey
- includes trailing space).stripPathPrefix
: (Boolean, optional) If set totrue
, thepathPrefix
will be removed from the request URL before forwarding it to thetargetUrl
. For example, ifpathPrefix
is/api
andstripPathPrefix
istrue
, a request tohttp://localhost:PORT/api/users
will be forwarded totargetUrl/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!