-
Notifications
You must be signed in to change notification settings - Fork 61
500 error when proxying application/json data #45
Comments
I've encountered the same thing with the current version. Requests with bodies fail to be proxied (see my PR for some details). As a temporary solution, you can try to use this branch in my fork (for example, |
Hi @pjacekm, I would be interested in your feedback; does the latest release of dyson fix the issues for you? |
Hi @webpro, thank you for your response. I have uninstalled the dyson package and then installed it again, effectively upgrading to version 0.7.0. Unfortunately, after upgrade it's even worse, all POST operations are failing with 500 error, even the ones that were working well before upgrading. |
That's unfortunate, @pjacekm. Any chance you could set up a case so I can investigate it further? |
I tried to investigate it further. The remote API is a third-party software and it'll be difficult for me to obtain their logs or meaningful feedback. I prepared 2 tests:
I must admit that I'm not a node developer, I hope I didn't commit any basic errors :) Let me describe my environment and all data I encounter relevant: I'm running node v. 4.2.2 on Mac OS "El Capitan". I've installed Dyson globally.
I've configured two local hosts in
Example data sent from HTTPRequester Firefox plugin is the following:
"dyson.json" contains the following configuration:
/post/test.js contains the following configuration:
Under "wrapper.test.local" the data is received as follows:
Changing "dyson.json" to proxy requests to the remote API (instead of the local environment) results in 500 Internal Server Errors:
When I'm using the request data as described in my initial post, after upgrading the Dyson package the news is that the request body is no longer an empty binary, however the remote API still responds with 500 errors. When I'm sending the same data to their API directly (without Dyson's intermediation) using the same client (HTTPRequester plugin), the operation is completed without errors. I'd appreciate your suggestions for other tests or debugging tools I might use to be able to solve the problem. |
Hi @pjacekm, if I understand correctly:
You say the remote API respond with error 500; I think what you mean by that is that you get the following message in the dyson logs: "500 INTERNAL SERVER ERROR". Is that correct? In that case, it might be very informative if you could edit the file Apparently your actual endpoint that does not work is HTTPS while your local endpoint that works is HTTP? That may be a lead. |
Hi @rixo, your assumptions were correct, and your suggestions were absolutely enlightening! I added
Interesting thing, when I changed
After defining a custom "Host" header in my request (I understand this is a malpractice?) the requests that I tested so far (more awaiting) went well. Is Dyson (or any of the libraries it uses) adding this Host header? I tested in two applications so far (Firefox plugin called HTTPRequester and DHC Restlet Chrome plugin) and in both cases "Host" header is automatically added. In the former app I can overwrite the "Host" header manually, but the latter doesn't let me to. |
So it seems that it's our side that is rejecting their certificate. Probably because it is self-signed? To confirm this diagnostic, you can try to add |
Their certificate doesn't look like self-signed to me, according to the "Issuer" info it was issued by DigiCert Inc. I added Anyway, I'm still getting 404 errors when the
I have modified
Probably not the most elegant solution, but the general idea serves our purpose. I still don't know how to match URLs with dynamic params, like Thank you very much for your help and great work on this useful project! |
As a follow-up... I'm trying to match the
When I use
instead of Is it an issue with the Dyson package, or that's how it works and there is no way to map |
Thanks for all you feedback. I think it eventually all come together. The Host header is added by the party making the request, and is mandatory according to HTTP specs. The problem is that currently we are just indiscriminately sending all the original request headers (in which Host point to the dyson server) to the target endpoint. This causes two issues. On our side, node's https module chokes when it verifies the certificate identity because (I think) it relies on the Host header to determine who we think we are talking to. On the other end, the Host header is needed by the reverse proxy (their nginx) to determine the actual target server. In the end, you were right: it all comes down to fixing the Host header. It can be done without the hassle to set it manually though. Simply replace this line by this:
The I don't know if you will still need to add custom headers to the request to the target endpoint, but for the record... Proxied requests are not registered into express with their own route by dyson, but with '*'; that's why your params are not mapped. You can change this by adding the following line in this place:
If you still need to access the dyson resource's config in proxy.js, you can use this version instead:
That will save you from having to look it up, which is fragile since express is totally OK with having multiple handlers matching the same route... Also, I think you should rename your option Finally, if you still need this option for something else than fixing the Host header, you should open another issue to request the feature with a bit of context about the use case in it. Hopefully this one will soon be finished. |
Hi @rixo, it makes a lot of sense now. The 500 errors were caused by node trying to verify the certificate, and the 404 errors were caused by a reverse proxy in front of the remote API. The point of intersection was a "Host" header, proxying values from the calling app to the remote API. I have removed I'd like to ask you one more question before closing the issue. Is it possible to create such configuration that would randomly allow part of the requests to the same resource get proxied, while some of them would generate mocked (locally defined) response? For example, let's say if the same resource URL Thanks again for your help! |
Thanks for a great discussion, guys. Will give it a more thorough read soon, but for now I wanted to respond to the "random proxy" question. Currently this is not possible with dyson. The paths that should be proxied are not registered with dyson at boot time. Once we would refactor this decision (to proxy the request or not) to (just before) the render process, the requested feature becomes an option. Perhaps simply by allowing the |
Thank you @webpro for your response. Actually, I liked the idea very much, it would give the user the option to decide whether he wants to proxy all requests, some of them (with the likeliness number) or none of them. In my opinion, such setting should be available at the individual resource config level, and the probability number could be an integer, say between 1 and 10, just to avoid playing with decimals and make this setting more clear to the users. Just my 2¢ ;) |
Is there a way to generate timed responses in Dyson? I'd like to simulate a delay in responses, but after 2+ hours of googling I still can't figure it out.
doesn't work, the response is send immediately, and after 10 seconds an error appears in console:
Edit: after some more testing I've seen that putting Also, I'd like to be able to simulate connection errors, for example "ECONNRESET" - is there a way to accomplish it in Dyson? I was trying:
but it works really strange. When invoked the first time, it's ok, but when called more times, the request gets executed twice. Might be a wrong location of I know such questions should be posted on some mailing list, but I think Dyson project doesn't have one? |
@pjacekm Please open new issues for new questions/topics. I'm actually the only creator/maintainer of this project, but I've been getting some great help from people like @rixo. On to your questions:
|
@webpro Thanks for your comments. My remarks follow:
I'll open a few new issues soon, let's see what happens. Thanks again for your help! |
I'm having issues trying to proxy application/json content to remote API.
and in the calling application (tried with DHC by Restlet Chrome plugin and HTTPRequester Firefox plugin) I see the following response:
Interesting thing is that the content (JSON) sent as "application/json" at the remote API is received as an empty binary (0-length binary content). When the same content is sent as "text/json", all works as expected (body content filled with data, no 500 errors).
I'm using the latest versions of nodejs and dyson (installed today) on Mac. Not having issues with proxying other requests (GET, PUT, etc.)
Thanks in advance for your suggestions and comments.
The text was updated successfully, but these errors were encountered: