-
Notifications
You must be signed in to change notification settings - Fork 2k
add beforeProxyRequest callback config option #1091
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
Conversation
provide beforeProxyRequest hook for manipulating outgoing request options (e.g., adding headers)
add description of beforeProxyRequest option update header re-writing example
test beforeProxyRequest fix header re-writing example in README
doc updates and test
👍 |
@Jeremy-iCars @rick-kilgore in this case why not just pass the headers in? I guess we could be more defensive in this case and not fire the event on post requests if it can have this type of unexpected consequences. I just think adding more options isnt the right solution. |
@jcrugzz Pass the headers in where? In my case, I need to dynamically choose what to send in the way of headers based on the request. Specifically, I'm supplying a default header value only if the original request does not contain the header. |
@rick-kilgore before you call |
My current understanding, is that the "proxyReq" callback is called too late for the purpouse of changing headers. What about moving the event emission of "proxyReq" at the end of setupOngoing, without adding a new event? As far as I understand from node-https-proxy, the only purpouse for this callback is to change headers, and this do not require a socket. In my case I want to remove headers and, sometimes, adding new headers on the basis of the reveived ones, so the flexibility provided by proxyReq callback seems to be required. |
@jcrugzz - now I see what you mean. I somehow got the mistaken impression that the function I pass into http.createServer() was being called only once at startup, instead of once for every request. I think my confusion was partly reinforced by the example for setting headers, though. You might want to change the example in the README to do it the way you're suggesting, since it won't work for POST requests the way it is. |
What if the header to be set is conditional? For instance, I have a post request that should be "If this header @jcrugzz Is this currently supported? |
+1, how do I do conditional header changes? Thanks. |
Fix for #867, and possibly these others: #908, #930, #889, #680.
This solution was suggested by @giuliopaci in #867. The problem with the header re-writing example in the README is that when you do a POST, the headers are sent before the 'proxyReq' event is fired. So you really have to add the headers before calling request(). This patch allows the user to register a synchronous callback that gets called in setupOutgoing() in which the caller can setup headers, or alter the outgoing request() options in whatever way desired.