I am so close I can almost touch it.
I have written the following:
//catch any connection event to this server
server.on('secureConnection', function (stream) {
//create a new buffer to hold what we are receiving in this stream
var receiveBuffer = new Buffer(0);
//store a link to the original ondata function so we can call it and
restore it
originalOnDataFunction = stream.ondata;
//declare a new ondata function for this stream
stream.ondata = function (d, start, end) {
//record what we have received
receiveBuffer = Buffer.concat([receiveBuffer, d.slice(start, end)]);
//if what we have received is greater than 4 (i.e. we have at least got
a GET request)
//then make changes
if (receiveBuffer.length >= 4) {
//reset the streams ondata function to the original
//this is all we want to edit for this connection
stream.ondata = originalOnDataFunction;
//if the first 11 characters of the buffer are 'MKCALENDAR ' then
make a change
if (receiveBuffer.toString('ascii', 0, 11) === 'MKCALENDAR ') {
//I change this to MKCOL /MKCALENDAR<rest of buffer> as this will
work with the node.js http parser
//and then I can check on the other side for a MKCOL method with
/MKCALENDAR as the start of the url and
//know that it was a MKCALENDAR method
var rewrittenBuffer = Buffer.concat([new Buffer('MKCOL
/MKCALENDAR', 'ascii'), receiveBuffer.slice(11)]);
//now call the original ondata function with this new buffer
stream.ondata.apply(this, [rewrittenBuffer, 0,
rewrittenBuffer.length]);
} else {
//no change needed just call the original ondata function with this
buffer
stream.ondata.apply(this, [receiveBuffer, 0, receiveBuffer.length]);
}
}
}
});
the server variable comes from a https.createServer function call.
However, it seems that some of the connections are just randomly dropped
somewhere. About 90-95% of them go through. Some connections will go
through sometimes and not others. Can anyone see what I am doing wrong?
This is a very neat solution if it would work and I think could be useful
to others.
Thanks in advance,
Mark
On Thursday, April 11, 2013 11:18:01 PM UTC+1, Isaac Schlueter wrote:
>
> Listen to the `secureConnection` event instead of the `connection`
> event. That'll give you the cleartextStream as an argument.
>
> On Thu, Apr 11, 2013 at 1:55 PM, Mark Jones
> <[email protected]<javascript:>>
> wrote:
> > Ben,
> >
> > Thanks for the hints. It is nice to see that others have raised this
> though
> > it is not clear if and when it will be included (it would be nice if it
> was
> > just included in a 0.10.? release soon instead of waiting all the way to
> > 0.12.0 - or at least for me the CALDAV methods of MKCALENDAR, ACL and
> > SCHEDULE.
> >
> > I looked at and tried node-parsley but did not have much luck. It
> didn't
> > seem to handle the http continue request very well and I would have to
> > collect the whole request before sending it on which seemed a little
> heavy.
> >
> > I also tried something like the following:
> >
> > server.on('connection',function(stream){
> > var receiveBuffer = new Buffer(0);
> >
> > stream.on("connect",function(){
> > console.log('stream connected');
> > });
> >
> > originalOnDataFunction = stream.ondata;
> > stream.ondata = function (d, start, end) {
> > //edit the method here i.e. change MKCALENDAR to MKCOL in the
> stream
> > and let my code work out the difference i.e. maybe add /MKCALENDAR to
> the
> > requested URL (or another method)
> > };
> > });
> >
> > However, in the above example the server is a https server (fully setup
> and
> > running - actually we are using it in a live production environment),
> and
> > the stream is encrypted and I cannot get access to the text in the
> stream.
> > If I could I could just change the string as described in the comment
> then
> > set stream.ondata=originalOnDataFunction again and let everything
> proceed as
> > normal - very efficient.
> >
> > Unless there is a way to get the unencrypted stream at that point I
> can't
> > see another way to do it. Just to use an apache server in the meantime
> > (hate the thought of going back to apache) and wait for the changes to
> come
> > into node.
> >
> > Thanks for all the great work - love node :)
> >
> > Mark
> >
> >
> > On Tuesday, April 9, 2013 4:12:59 PM UTC+1, Ben Noordhuis wrote:
> >>
> >> On Tue, Apr 9, 2013 at 4:56 PM, Mark Jones <[email protected]>
>
> >> wrote:
> >> > I am attempting to create a CALDAV server for which node.js is a
> reverse
> >> > proxy. CALDAV has some extended (or custom) HTTP request methods and
> >> > these
> >> > seem to cause a problem in node. The method in question for me is
> >> > MKCALENDAR. When I make a request with this request method in the
> >> > header
> >> > the request just seems to die with no error or response at all.
> >> > Is there a work around for this?
> >> >
> >> > Thanks
> >> >
> >> > Mark
> >>
> >> Custom HTTP methods aren't supported right now (but see [1]). There
> >> is a pull request for the http-parser component[2] but admittedly
> >> review kind of stalled. Mea culpa.
> >>
> >> There are ways around the current limitation - mostly by intercepting
> >> and rewriting the first few bytes of the request - but they require
> >> knowledge of node.js internals and are likely to break on the next
> >> upgrade.
> >>
> >> Something like [3] may be a good solution for you.
> >>
> >> [1] https://github.com/joyent/node/issues/3192
> >> [2] https://github.com/joyent/http-parser/pull/145
> >> [3] https://github.com/substack/node-parsley
> >
> > --
> > --
> > Job Board: http://jobs.nodejs.org/
> > Posting guidelines:
> > https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
> > You received this message because you are subscribed to the Google
> > Groups "nodejs" group.
> > To post to this group, send email to [email protected]<javascript:>
> > To unsubscribe from this group, send email to
> > [email protected] <javascript:>
> > For more options, visit this group at
> > http://groups.google.com/group/nodejs?hl=en?hl=en
> >
> > ---
> > You received this message because you are subscribed to the Google
> Groups
> > "nodejs" group.
> > To unsubscribe from this group and stop receiving emails from it, send
> an
> > email to [email protected] <javascript:>.
> > For more options, visit https://groups.google.com/groups/opt_out.
> >
> >
>
--
--
Job Board: http://jobs.nodejs.org/
Posting guidelines:
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en
---
You received this message because you are subscribed to the Google Groups
"nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.