Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@
*/

import Proxy from './proxy'
import { setConfig } from './request'

export default {
Proxy: Proxy,
createServer: function(opts) {
return new Proxy(opts)
},
setConfig,
}
36 changes: 20 additions & 16 deletions src/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,25 @@ import url from 'url'
import querystring from 'querystring'
import assert from 'assert'

let validProtocols = {
'http:': true,
'https:': true,
let config = {
validProtocols: {
'http:': true,
'https:': true,
},
removeHeaders: {
'accept-encoding': true, // until proxy handles gzip
'proxy-connection': true,
'proxy-authorization': true,
},
nonEntityMethods: {
GET: true,
HEAD: true,
TRACE: true,
},
}

let removeHeaders = {
'accept-encoding': true, // until proxy handles gzip
'proxy-connection': true,
'proxy-authorization': true,
}

let nonEntityMethods = {
GET: true,
HEAD: true,
TRACE: true,
export function setConfig(_config) {
config = _config;
}

/**
Expand All @@ -44,7 +48,7 @@ export default class Request extends Body {
}

set protocol(protocol){
if (!validProtocols.hasOwnProperty(protocol)) {
if (!config.validProtocols.hasOwnProperty(protocol)) {
throw new Error('invalid protocol: ' + protocol) // TODO: test this
}
this._setRawDataItem('protocol', protocol)
Expand Down Expand Up @@ -211,7 +215,7 @@ export default class Request extends Body {

// TODO: emit debug log events for things that are changed.
_finalize(){
if (nonEntityMethods.hasOwnProperty(this.method)) {
if (config.nonEntityMethods.hasOwnProperty(this.method)) {
this.string = '' // TODO: test
}
if (!this._source){
Expand All @@ -230,7 +234,7 @@ export default class Request extends Body {

Object.keys(this.headers).forEach(name => {
// TODO: test
if (removeHeaders.hasOwnProperty(name)) {
if (config.removeHeaders.hasOwnProperty(name)) {
delete this.headers[name]
} else if (this.headers[name] === undefined){
delete this.headers[name]
Expand Down