oboe.js
oboe.js copied to clipboard
Pass Other Options to Node Request
I could be wrong though based on the following code it does not seem possible to pass on additional parameters to the underlying request call.
https://github.com/jimhigson/oboe.js/blob/master/dist/oboe-node.js#L1159
The code seems to support passing the following parameters:
hostname: parsedUrl.hostname,
port: parsedUrl.port,
path: parsedUrl.path,
method: method,
headers: headers,
protocol: parsedUrl.protocol
...though there are other potential agent options that can be passed. Is it possible to support this?
host: A domain name or IP address of the server to issue the request to. Defaults to 'localhost'. hostname: To support url.parse() hostname is preferred over host port: Port of remote server. Defaults to 443. method: A string specifying the HTTP request method. Defaults to 'GET'. path: Request path. Defaults to '/'. Should include query string if any. E.G. '/index.html?page=12' headers: An object containing request headers. auth: Basic authentication i.e. 'user:password' to compute an Authorization header. agent: Controls Agent behavior. When an Agent is used request will default to Connection: keep-alive. Possible values: undefined (default): use globalAgent for this host and port. Agent object: explicitly use the passed in Agent. false: opts out of connection pooling with an Agent, defaults request to Connection: close. The following options from tls.connect() can also be specified. However, a globalAgent silently ignores these.
pfx: Certificate, Private key and CA certificates to use for SSL. Default null. key: Private key to use for SSL. Default null. passphrase: A string of passphrase for the private key or pfx. Default null. cert: Public x509 certificate to use. Default null. ca: An authority certificate or array of authority certificates to check the remote host against. ciphers: A string describing the ciphers to use or exclude. Consult http://www.openssl.org/docs/apps/ciphers.html#CIPHER_LIST_FORMAT for details on the format. rejectUnauthorized: If true, the server certificate is verified against the list of supplied CAs. An 'error' event is emitted if verification fails. Verification happens at the connection level, before the HTTP request is sent. Default true. secureProtocol: The SSL method to use, e.g. TLSv1_method to force TLS version 1. The possible values depend on your installation of OpenSSL and are defined in the constant SSL_METHODS.
Are these things that it's possible to do with request
? If so, one thing that you can do is initiate the request, store it into a variable and pass that stream into oboe. Here's my guess as to what that code would look like:
var request = require('request');
var options = {
method: 'POST',
uri: 'http://service.com/upload',
host: '', //A domain name or IP address of the server to issue the request to. Defaults to 'localhost'.
hostname: '', //To support url.parse() hostname is preferred over host
port: '', //Port of remote server. Defaults to 443.
method: '', //A string specifying the HTTP request method. Defaults to 'GET'.
path: '', //Request path. Defaults to '/'. Should include query string if any. E.G. '/index.html?page=12'
headers: '', //An object containing request headers.
auth: '', //Basic authentication i.e. 'user:password' to compute an Authorization header.
agent: '', //Controls Agent behavior. When an Agent is used request will default to Connection: keep-alive. Possible values:
}
var stream = request(options);
oboe(stream)
.node(funciton(data){
// do stuff with data
})
The above is from the node documentation though I think everything one would generally need would be supported via request. i.e. that solution would work.
It seems like this can be accomplished by BYO-streams. However, maybe we can talk about the pros and cons of supporting other options inside oboe as opposed to passing them in from outside.
One advantage would be that this would be that passing more options would then be possible on the front end, instead of just in Node. This would be a mute point if it was possible to stream a request on the front end and pass it to oboe, but I'm not sure if it is.
Another thing on my mind (I don't know all that much about HTTP), what options are actually possible? Can you pass anything as an option and it's up to the server to know how to support it? Does that mean we can just parse the options we care about and pass the rest to the request?
@blueshirts where did you find all of those options in the node docs? I would like to try to find more information about options.
Late to this but I too needed to have more HTTP options available and be able to support the host environment HTTP_PROXY. I ended up creating my own stream using request.js which should mostly provide drop-in support, emitting the same events as the bundled one i.e "start". I've not tested beyond my own use case though.
https://www.npmjs.com/package/oboe-stream-request