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

mitm return 400 on custom methods #63

Closed
Oloompa opened this issue Dec 9, 2019 · 4 comments
Closed

mitm return 400 on custom methods #63

Oloompa opened this issue Dec 9, 2019 · 4 comments

Comments

@Oloompa
Copy link

Oloompa commented Dec 9, 2019

RFC 2616 and 7540 allow use of custom methods.

When we use other methods, mitm always return 400 without running request event.

@moll
Copy link
Owner

moll commented Dec 9, 2019

Hey,

While I'm not sure what responds with 400 instead of just blowing up, you're right that Mitm.js doesn't seem to support custom HTTP methods. Node.js v6 for example just throws "socket hang up". Turns out Node.js' web server itself doesn't support custom HTTP methods — nodejs/node-v0.x-archive#3192. That came as a surprise to me. Because Mitm.js delegates HTTP request parsing to Node.js itself, Mitm.js can't support custom methods out of the box either.

If you've got a custom HTTP parser, you could, however, hack support for that, I suppose, by overwriting Mitm.prototype.request (https://github.com/moll/node-mitm/blob/master/index.js#L146) and not invoking the default Http._connectionListener. Instead, get the request body from the socket.serverSocket and parse that yourself, finally triggering request on the Mitm instance.

Let me know what you decide to do.

@moll
Copy link
Owner

moll commented Dec 9, 2019

I've added a note to the README: https://github.com/moll/node-mitm#custom-http-methods.

@Oloompa
Copy link
Author

Oloompa commented Dec 9, 2019

I didn't notice nodejs was blocking custom methods.
The "issue" has been open in 2012 for nodejs without any move.
I will probably take a look on deno.

@moll
Copy link
Owner

moll commented Dec 9, 2019

I didn't know that either. Seems like a fairly arbitrary limitation on Node.js's part.
I'll close the issue as there's not much to do right now, but we can continue chatting.

@moll moll closed this as completed Dec 9, 2019
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

No branches or pull requests

2 participants