-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Allow proxy config per request #1045
Comments
Thanks for adding this issue! Unfortunately, this is going to need further evaluation in order to be implemented without introducing any performance regressions. My concern regarding performance stems from the fact that the proxy is configured in the This issue, together with #970 ( Something like this: import http from "k6/http";
let myClient = http.NewClient({
proxy: "https://myproxy",
forceHTTP1: true,
// ... other options like the h2c ones, tls versions, etc.
});
export default function () {
myClient.get("https://httpbin.org/");
// ...
} This won't stop you from using a different proxy for each individual request, as you want for your use case, though it will make it slightly more verbose than just specifying the proxy as a parameter to the Some other things that need to be considered:
|
Hm ... I think this will work and it is somewhat (a lot IMO) similar to how golang stdlib does things. I would prefer, though, to first somewhat fix the configuration mess and than add even more ... configuration. I also think that the part with changing the default clients practically implements #761. I myself too think that having cli option for everything is overkill and probably not very useful (as I have said before :)). |
Another somewhat connected issue that could be more easily implemented if we had support for creating custom HTTP clients: #857 |
@mstoykov, this would need further evaluation, but I'm not sure the best places for things like common headers and such is the HTTP client. The reason for that is that groups of HTTP requests with completely different headers could still share the same underlying HTTP transport and reuse the same previously opened connections. It's basically also muddling the abstractions, just in the opposite way of having the proxy be configured per-request. Added to that, I think the use cases for the custom transports I listed or linked above are different than the use cases for custom HTTP request headers, cookies, metric tags, response types, timeouts, etc. I imagine that I'd like to configure those much more often than I'd like a new transport, for situations like that: let loginData = http.post("https://myapp.com/login")
group("logged in data", doUserStuffOnTheWebsiteCallback, {
http: {headers: {
"Authorization": loginData.json().blah,
}},
tags: {myCustomMetricTag: "loggedInStuff"},
}) In a use case like that, there's no need to use a different transport, it would actually be somewhat counter-productive. |
How to pass the proxies details with http.post in k6? I am having issue due to the proxy and I couldn't get the access_token. I am able to get the token for the same with python code when I pass the proxy details but similar error without proxy, So I figure it out the issue is due to the proxy but how do I pass proxy in k6?
import http from "k6/http";
export function getAccessToken(clientId, clientSecret, grant_type, auth_url) {
const data = {
client_id: clientId,
client_secret: clientSecret,
grant_type: grant_type,
};
// let myClient = http.NewClient({
// proxy: {
// http: "http://proxy...",
// https: "http://proxy...",
// },
// });
let res = http.post(auth_url, data, {
headers: {
"Content-Type'": "application/x-www-form-urlencoded",
},
});
return res;
} |
@baralraj, The only way to currently specify a HTTP(s) proxy is globally, one proxy for the whole test run, via the semi-standard |
Thank you, do you have any example of how we can set the proxy globally? If yes, can you provide the reference link of that? I already tried something like this |
How to set the environment variable depends on the OS, in linux and mac you can just use HTTP_PROXY=localhost:8888 k6 run script.js or
In windows I think you can use |
I am facing a similar issue, but no solution had been found. So I developed a new k6 extension to resolve my own issue. Example: import http from 'k6/http';
import proxy from 'k6/x/proxy';
const YOUR_PROXY = 'http://user:[email protected]'
export default function () {
proxy.setProxy(YOUR_PROXY)
const resp = http.get('http://httpbin.test.k6.io/get')
proxy.clearProxy()
} |
When setting up a request to be sent, being able to set a proxy for every request would be very helpful for my use case. We need to test our proxy code to ensure it's stable and being able to create a different proxy for each VU would be great.
Currently it only suports a single HTTP proxy.
The text was updated successfully, but these errors were encountered: