Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added haxe.Http support for nodejs #4713

Merged
merged 4 commits into from
Jul 19, 2016

Conversation

hexonaut
Copy link
Contributor

@hexonaut hexonaut commented Dec 8, 2015

No description provided.

@ncannasse
Copy link
Member

@nadako can you check + merge ?

@nadako
Copy link
Member

nadako commented Dec 8, 2015

I haven't used haxe.Http myself, but sure, I'll check it out :-)

@nadako
Copy link
Member

nadako commented Dec 8, 2015

We don't have tests for haxe.Http, right?

@Simn
Copy link
Member

Simn commented Dec 8, 2015

Not really, last time I tried to set that up it ended in tears.

@nadako
Copy link
Member

nadako commented Dec 8, 2015

@Blank101 It's missing onStatus functionality, also I think it makes sense to make requestUrl unavailable with -D nodejs since there's no way to do sync request on node.js and it'll always return null.

@hexonaut
Copy link
Contributor Author

hexonaut commented Dec 8, 2015

Oops missed the onStatus, and yes requestUrl, withCredentials and async should be unavailable.

@nadako
Copy link
Member

nadako commented Dec 8, 2015

Another thing that's missing is setting multiple headers of the same name. It seems that it's also missing in hxnodejs externs though. We'll have to look at how to do it in node.js.

protocol: secure ? "https:" : "http:",
host: host,
port: port,
method: post == true ? 'POST' : 'GET',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

post == true, seriously? :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

post could be null, no?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lol I guess that doesn't make a difference for js target..

@nadako
Copy link
Member

nadako commented Dec 8, 2015

added some more comments. to be honest, I think we should refactor haxe.Http asap

@hexonaut
Copy link
Contributor Author

hexonaut commented Dec 8, 2015

Made the change, and yes I agree about refactoring haxe.Http. It's a mess right now.

@Simn
Copy link
Member

Simn commented Dec 8, 2015

I would also prefer to see this thing refactored before we add any more stuff to it...

#if js
#if nodejs
me.responseData = null;
var url_regexp = ~/^(https?:\/\/)?([a-zA-Z\.0-9_-]+)(:[0-9]+)?(.*)$/;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't it be easier to use js.node.Url.parse instead of own solution?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would probably make it easier to maintain. I just copied the regex from the customRequest.

@nadako
Copy link
Member

nadako commented Dec 8, 2015

Okay, about multiple headers with same name, it seems that node.js supports passing array of string instead of string for the header value. I'll update the hxnodejs extern, meanwhile please add support for that in haxe.Http.

@hexonaut
Copy link
Contributor Author

hexonaut commented Dec 8, 2015

The resource you posted is for http response headers, not request.

@nadako
Copy link
Member

nadako commented Dec 8, 2015

Yes, but actually getHeader/setHeader are methods of OutgoingMessage class that is base for both ClientRequest and ServerResponse. Node.js documentation is really awful.

@nadako
Copy link
Member

nadako commented Dec 8, 2015

And those methods are used to set headers passed as headers field to the request options.

@hexonaut
Copy link
Contributor Author

Are we able to merge this in for the time being, and defer the refactor to some point in the future? This is a pretty critical feature for nodejs users.

@nadako
Copy link
Member

nadako commented May 23, 2016

I don't know, this introduces dependency on hxnodejs in the std code and I'm not sure this is a good idea. I'd rather go for HaxeFoundation/hxnodejs#69

@nadako nadako merged commit c98742c into HaxeFoundation:development Jul 19, 2016
@nadako
Copy link
Member

nadako commented Jul 19, 2016

This can't go into hxnodejs because of HaxeFoundation/hxnodejs#42, so I just merged this at last.

@hexonaut hexonaut deleted the nodejs_http branch July 19, 2016 01:56
@back2dos
Copy link
Member

This can't go into hxnodejs because of HaxeFoundation/hxnodejs#42, so I just merged this at last.

Can you elaborate? I offered a solution for having a node-specific Bytes implementation but I fail to see how it's related to Http.

I really think we should either add nodejs to the std lib or put http for nodejs into hxnodejs. This kind of mix is pretty horrible.

@nadako
Copy link
Member

nadako commented Jul 19, 2016

Can you elaborate?

If I just redefine haxe.Http in hxnodejs it will break usage of haxe.Http macros. I tried adding it to js/_std/haxe/Http.hx but that doesn't seem to work for libraries either. There's an open issue discussing a possible solution: #4249, but that's for the future.

I'm yet to try the solution you suggested here HaxeFoundation/hxnodejs#42 (comment). It sounds like it might actually work, but still feels hacky to me (still an option tho).

I really think we should either add nodejs to the std lib or put http for nodejs into hxnodejs. This kind of mix is pretty horrible.

Well we used to depend on hxssl for the https support, this isn't very different.

@back2dos
Copy link
Member

I'm yet to try the solution you suggested here HaxeFoundation/hxnodejs#42 (comment). It sounds like it might actually work, but still feels hacky to me (still an option tho).

I'm using this technique quite a lot. Maybe it's a hack (I guess overwriting a std class probably always will be). But it is isolated and allows for clean separation on the scale that really matters. Once better features are available, it is trivial to replace the hack.

Well we used to depend on hxssl for the https support, this isn't very different.

Yes and that was horrible. I agree this isn't very different, particularly in that this is horrible too :D

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants