1.0.0 • Published 4 years ago
corrosion v1.0.0
Corrosion
Titanium Networks main web proxy. Successor to Alloy
Installation:
npm i corrosionExample:
const Corrosion = require('corrosion');
const proxy = new Corrosion();
const http = require('http')
http.createServer((req, res) =>
proxy.request(req, res) // Request Proxy
).on('upgrade', (req, socket, head) =>
proxy.upgrade(req, socket, head) // WebSocket Proxy
).listen(80);Much more in depth one is in the demo folder.
API:
Index
configprefixString - URL Prefixtitle(Boolean / String) - Title used for HTML documentswsBoolean - WebSocket rewritingcookieBoolean - Request CookiescodecString - URL encoding (base64, plain, xor).requestMiddlewareArray - Array of middleware functions for proxy request (Server).responseMiddlewareArray - Array of middleware functions for proxy response (Server).standardMiddlewareBoolean - Use the prebuilt middleware used by default (Server).
request
requestRequestresponseResponse
upgrade
requestRequestsocketSocketheadHead
bundleScripts
Bundles scripts for client injection. Important when updating proxy.
Properties
url
wrap
valStringconfigConfigurationbaseWHATWG URLoriginLocation origin - Adds a location origin before the proxy urlflagsArray - 'xhr' => /service/xhr_/https%3A%2F%2Fexample.org/
unwrap
valStringconfigConfigurationoriginLocation origin - Required if a location origin starts before the proxy urlflagsBoolean - Returns with both the URL and flags found { value: 'https://example.org', flags: 'xhr', })leftoversBoolean - Use any leftovers if any after the encoded proxy url
Properties
regexRegex used to determine to rewrite the URL or not.prefixURL Prefixcodec(base64, plain, xor)
js
process
sourceJS scripturlURL for heading
iterate
astJS ASTCallbackHandler initated on AST node
createHead
urlURL for heading
createCallExperssion
calleeAcorn.js NodeargsArray
createArrayExpression
elementsArray
createIdentifier
nameIdentifier namepreventRewritePrevent further rewrites
createLiteral
valueLiteral value
css
process
sourceCSSconfigConfigurationbaseWHATWG URLoriginLocation origincontextCSS-Tree context
html
process
sourceHTML SourceconfigConfigurationdocumentDetermines of its a document or fragment for parsingbaseWHATWG URLoriginLocation origin
source
processedRewritten HTMLconfigConfigurationdocumentDetermines of its a document or fragment for parsing
Properties
mapMap for attribute rewriting
cookies
encode
inputNew (Cookie / Cookies)configConfigurationurlWHATWG URLdomainCookie DomainsecureCookie Secure
decode
storeEncoded CookiesconfigConfigurationurlWHATWG URL
codec
encode
decode
strString
middleware
Middleware are functions that will be executed either before request or after response. These can alter the way a request is made or response is sent.
function(ctx) {r
ctx.body; // (Request / Response) Body (Will return null if none)
ctx.headers; // (Request / Response) Headers
ctx.url; // WHATWG URL
ctx.flags; // URL Flags
ctx.origin; // Request origin
ctx.method; // Request method
ctx.rewrite; // Corrosion object
ctx.statusCode; // Response status (Only available on response)
ctx.agent; // HTTP agent
ctx.address; // Address used to make remote request
ctx.clientSocket; // Node.js Server Socket (Only available on upgrade)
ctx.clientRequest; // Node.js Server Request
ctx.clientResponse; // Node.js Server Response
ctx.remoteResponse; // Node.js Remote Response (Only available on response)
};Default middleware
Request
- requestHeaders
Response
- responseHeaders
- decompress
- rewriteBody
Available Middleware
address (Request)
arrArray of IP addresses to use in request
const Corrosion = require('corrosion');
const proxy = new Corrosion({
requestMiddleware: [
Corrosion.middleware.address([
0.0.0.0,
0.0.0.0
]),
],
});blacklist
arrArray of hostnames to block clients from seeingpageBlock page
const Corrosion = require('corrosion');
const proxy = new Corrosion({
requestMiddleware: [
Corrosion.middleware.blacklist([
'example.org',
'example.com',
], 'Page is blocked'),
],
});1.0.0
4 years ago