Skip to content

Commit

Permalink
pass request by reference
Browse files Browse the repository at this point in the history
  • Loading branch information
flotwig committed Sep 26, 2019
1 parent 71487d4 commit d921ae7
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 2 deletions.
6 changes: 6 additions & 0 deletions packages/proxy/lib/http/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ const READONLY_MIDDLEWARE_KEYS : (keyof HttpMiddlewareThis<{}>)[] = [
'buffers',
'config',
'getRemoteState',
'request',
'next',
'end',
'onResponse',
Expand All @@ -59,6 +60,7 @@ type HttpMiddlewareThis<T> = HttpMiddlewareCtx<T> & Readonly<{
buffers: HttpBuffers
config: any
getRemoteState: () => any
request: any

next: () => void
/**
Expand Down Expand Up @@ -173,16 +175,19 @@ export class Http {
config: any
getRemoteState: () => any
middleware: MiddlewareStacks
request: any

constructor (opts: {
config: any
getRemoteState: () => any
middleware?: MiddlewareStacks
request: any
}) {
this.buffers = new HttpBuffers()

this.config = opts.config
this.getRemoteState = opts.getRemoteState
this.request = opts.request

if (typeof opts.middleware === 'undefined') {
this.middleware = {
Expand All @@ -203,6 +208,7 @@ export class Http {
buffers: this.buffers,
config: this.config,
getRemoteState: this.getRemoteState,
request: this.request,
middleware: _.cloneDeep(this.middleware),
}

Expand Down
2 changes: 1 addition & 1 deletion packages/proxy/lib/http/request-middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ const SendRequestOutgoing : RequestMiddleware = function () {
requestOptions.url = requestOptions.url.replace(remoteState.origin, remoteState.fileServer)
}

const req = request.create(requestOptions)
const req = this.request.create(requestOptions)

req.on('error', this.onError)
req.on('response', (incomingRes) => this.onResponse(incomingRes, req))
Expand Down
1 change: 1 addition & 0 deletions packages/proxy/lib/network-proxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export class NetworkProxy {
config: any
getRemoteState: () => any
middleware?: any
request: any
}) {
this.http = new Http(opts)
}
Expand Down
2 changes: 1 addition & 1 deletion packages/server/lib/server.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ class Server

getRemoteState = => @_getRemoteState()

@_networkProxy = new NetworkProxy({ config, getRemoteState })
@_networkProxy = new NetworkProxy({ config, getRemoteState, request: @_request })

@createHosts(config.hosts)

Expand Down

0 comments on commit d921ae7

Please sign in to comment.