forked from cypress-io/cypress
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor proxy into own package, implement middleware pattern (cypres…
…s-io#5136) * renames * Refactor proxy into own package, implement middleware pattern don't need these mocha opts anymore fix test no more zunder READMEs fix test * pass request by reference * fix cors path * Move replace_stream to proxy, concat-stream util in network * Pin dependency versions * Revert addDefaultPort behavior * Add READMEs for proxy, network * Update README.md * eslint --fix * set to null not undefined * use delete and bump node types * import cors from package now * parse-domain@2.3.4 * proxy package needs common-tags * move pumpify dep * load through where it's needed, remove unused passthru_stream * remove unneeded getbuffer call Co-authored-by: Gleb Bahmutov <gleb.bahmutov@gmail.com>
- Loading branch information
Showing
55 changed files
with
1,591 additions
and
793 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
# network | ||
|
||
This package contains networking-related classes and utilities. | ||
|
||
## Exports | ||
|
||
You can see a list of the modules exported from this package in [./lib/index.ts](./lib/index.ts). Here is a brief description of what's available: | ||
|
||
* `agent` is a HTTP/HTTPS [agent][1] with support for HTTP/HTTPS proxies and keepalive whenever possible | ||
* `allowDestroy` can be used to wrap a `net.Server` to add a `.destroy()` method | ||
* `blacklist` is a utility for matching glob blacklists | ||
* `concatStream` is a wrapper around [`concat-stream@1.6.2`][2] that makes it always yield a `Buffer` | ||
* `connect` contains utilities for making network connections, including `createRetryingSocket` | ||
* `cors` contains utilities for Cross-Origin Resource Sharing | ||
* `uri` contains utilities for URL parsing and formatting | ||
|
||
See the individual class files in [`./lib`](./lib) for more information. | ||
|
||
## Installing Dependencies | ||
|
||
```shell | ||
npm i | ||
``` | ||
|
||
## Building | ||
|
||
Note: you should not ever need to build the .js files manually. `@packages/ts` provides require-time transpilation when in development. | ||
|
||
```shell | ||
npm run build-js | ||
``` | ||
|
||
## Testing | ||
|
||
Tests are located in [`./test`](./test) | ||
|
||
To run tests: | ||
|
||
```shell | ||
npm run test | ||
``` | ||
|
||
[1]: https://devdocs.io/node/http#http_class_http_agent | ||
[2]: https://github.com/maxogden/concat-stream/tree/v1.6.2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import _ from 'lodash' | ||
import minimatch from 'minimatch' | ||
import { stripProtocolAndDefaultPorts } from './uri' | ||
|
||
export function matches (urlToCheck, blacklistHosts) { | ||
// normalize into flat array | ||
blacklistHosts = [].concat(blacklistHosts) | ||
|
||
urlToCheck = stripProtocolAndDefaultPorts(urlToCheck) | ||
|
||
// use minimatch against the url | ||
// to see if any match | ||
const matchUrl = (hostMatcher) => { | ||
return minimatch(urlToCheck, hostMatcher) | ||
} | ||
|
||
return _.find(blacklistHosts, matchUrl) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import _ from 'lodash' | ||
import _concatStream from 'concat-stream' | ||
|
||
type Callback = (buf: Buffer) => void | ||
type ConcatOpts = { | ||
encoding?: string | ||
} | ||
|
||
/** | ||
* Wrapper for `concat-stream` to handle empty streams. | ||
*/ | ||
export const concatStream: typeof _concatStream = function (opts: Callback | ConcatOpts, cb?: Callback) { | ||
let _cb: Callback = cb! | ||
|
||
if (!_cb) { | ||
_cb = opts as Callback | ||
opts = {} | ||
} | ||
|
||
return _concatStream(opts as ConcatOpts, function (buf: Buffer) { | ||
if (!_.get(buf, 'length')) { | ||
// concat-stream can give an empty array if the stream has | ||
// no data - just call the callback with an empty buffer | ||
return _cb(Buffer.from('')) | ||
} | ||
|
||
return _cb(buf) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,17 @@ | ||
import agent from './agent' | ||
import * as blacklist from './blacklist' | ||
import * as connect from './connect' | ||
import { allowDestroy } from './allow-destroy' | ||
import * as cors from './cors' | ||
import * as uri from './uri' | ||
|
||
export { | ||
agent, | ||
allowDestroy, | ||
blacklist, | ||
connect, | ||
cors, | ||
uri, | ||
} | ||
|
||
export { allowDestroy } from './allow-destroy' | ||
|
||
export { concatStream } from './concat-stream' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
test/unit | ||
test/integration | ||
--compilers ts:@packages/ts/register | ||
--compilers ts:@packages/ts/register,coffee:@packages/coffee/register | ||
--timeout 10000 | ||
--recursive |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 3 additions & 4 deletions
7
packages/server/test/unit/cors_spec.js → packages/network/test/unit/cors_spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.