Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
… into main
  • Loading branch information
caracal-js committed Jul 28, 2021
2 parents 8a85169 + 4f1e9df commit d6fdcb7
Showing 1 changed file with 115 additions and 32 deletions.
147 changes: 115 additions & 32 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,79 +23,162 @@ npm i corrosion
const Corrosion = require('corrosion');
const proxy = new Corrosion();
const http = require('http')
http.createServer((req, res) => proxy.request(req, res)).on('upgrade', proxy.upgrade).listen(80);
http.createServer((req, res) => proxy.request(req, res)).on('upgrade', (req, socket, head) => proxy.upgrade(req, socket, head)).listen(80);
```
Much more in depth one is in the `demo` folder.
Much more in depth one is in the [demo folder](demo/).

# API:


# Index
## Index
- `config`
- `config.prefix` (String) URL Prefix
- `config.title` (Boolean / String) Title used for HTML documents
- `config.ws` (Boolean) WebSocket rewriting
- `config.cookie` (Boolean) Request Cookies
- `config.codec` (String) URL encoding (base64, plain, xor).
- `config.requestMiddleware` (Array) Array of middleware functions for proxy request.
- `config.responseMiddleware` (Array) Array of middleware functions for proxy response.
- `config.standardMiddleware` (Boolean) Use the prebuilt middleware used by default.
- `prefix` String - URL Prefix
- `title` (Boolean / String) - Title used for HTML documents
- `ws` Boolean - WebSocket rewriting
- `cookie` Boolean - Request Cookies
- `codec` String - URL encoding (base64, plain, xor).
- `requestMiddleware` Array - Array of [middleware](#middleware) functions for proxy request (Server).
- `responseMiddleware` Array - Array of [middleware](#middleware) functions for proxy response (Server).
- `standardMiddleware` Boolean - Use the prebuilt [middleware](#middleware) used by default (Server).

#### request
- `request` Request
- `response` Response

#### upgrade
- `request` Request
- `socket` Socket
- `head` Head

# JS Rewriter
## Properties
- [url](#url)
- [html](#html)
- [js](#js)
- [css](#css)
- [cookies](#cookies)
- [config](#index)
- [codec](#codec)
- [prefix](#url)



## url

#### wrap
- `val` String
- `config` Configuration
- `base` WHATWG URL
- `origin` Location origin - Adds a location origin before the proxy url
- `flags` Array - ['xhr'] => /service/xhr_/https%3A%2F%2Fexample.org/

#### unwrap
- `val` String
- `config` Configuration
- `origin` Location origin - Required if a location origin starts before the proxy url
- `flags` Boolean - Returns with both the URL and flags found { value: 'https://example.org', flags: ['xhr'], })
- `leftovers` Boolean - Use any leftovers if any after the encoded proxy url

## Methods:

### process
## Properties
- `regex` Regex used to determine to rewrite the URL or not.

- `prefix` URL Prefix

- `codec` (base64, plain, xor)


## js

#### process
- `source` JS script
- `url` URL for heading

### iterate
#### iterate
- `ast` JS AST
- `Callback` Handler initated on AST node

### createHead
#### createHead
- `url` URL for heading

### createCallExperssion
#### createCallExperssion
- `callee` Acorn.js Node
- `args` Array

### createArrayExpression
#### createArrayExpression
- `elements` Array

### createIdentifier
#### createIdentifier
- `name` Identifier name
- `preventRewrite` Prevent further rewrites

### createLiteral
#### createLiteral
- `value` Literal value

# CSS Rewriter

## Methods:
## css

### process:
#### process
- `source` CSS
- `config` Configuration
- `base` WHATWG URL Instance
- `base` WHATWG URL
- `origin` Location origin
- `context` CSS-Tree context

# HTML Rewriter
## html

## Methods:

### process:
#### process
- `source` HTML Source
- `config` Configuration
- `document` Determines of its a document or fragment for parsing
- `base` WHATWG URL Instance
- `base` WHATWG URL
- `origin` Location origin

### source:
#### source
- `processed` Rewritten HTML
- `config` Configuration
- `document` Determines of its a document or fragment for parsing

## Properties
### Properties
- `map` Map for attribute rewriting


## cookies

#### encode
- `input` New (Cookie / Cookies)
- `config` Configuration
- `url` WHATWG URL
- `domain` Cookie Domain
- `secure` Cookie Secure

#### decode
- `store` Encoded Cookies
- `config` Configuration
- `url` WHATWG URL

## codec

#### encode
#### decode
- `str` String

## 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.

```javascript
function(ctx) {
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.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)
};
```

0 comments on commit d6fdcb7

Please sign in to comment.