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

ProxySettings.port ignored #28951

Closed
2 of 6 tasks
drizzd opened this issue Mar 18, 2024 · 3 comments
Closed
2 of 6 tasks

ProxySettings.port ignored #28951

drizzd opened this issue Mar 18, 2024 · 3 comments
Assignees
Labels
Azure.Core bug This issue requires a change to an existing behavior in the product in order to be resolved. Client This issue points to a problem in the data-plane of the library. customer-reported Issues that are reported by GitHub users external to the Azure organization. needs-team-attention Workflow: This issue needs attention from Azure service team or SDK team

Comments

@drizzd
Copy link

drizzd commented Mar 18, 2024

  • Package Name: @azure/core-rest-pipeline
  • Package Version: 1.15.0
  • Operating system: Ubuntu
  • nodejs
    • version: 18
  • browser
    • name/version:
  • typescript
    • version: 5.4.2
  • Is the bug related to documentation in

Describe the bug
In commit ba2f5e6 the ProxyPolicy was refactored between 1.14.0 and 1.15.0. In 1.14.0, ProxySettings.port is added to HttpsProxyAgentOptions. Since 1.15.0, only the ProxySettings.host is used. ProxySettings.port is not used.

To Reproduce
Steps to reproduce the behavior:

Run the following code with @azure/core-rest-pipeline version 1.15.0 or later.

import { PipelineRequest, createDefaultHttpClient } from '@azure/core-rest-pipeline';
import { CommonClientOptions } from '@azure/core-client';
import { DefaultAzureCredential } from '@azure/identity';
import { ContainerRegistryManagementClient } from '@azure/arm-containerregistry';

async function main() {
    const httpClient = createDefaultHttpClient();
    const clientOptions: CommonClientOptions = {
        proxyOptions: {
            host: 'http://proxy.example.com',
            port: 8080,
        },
        httpClient: {
            sendRequest: async (request: PipelineRequest) => {
                console.log('request', request);
                return httpClient.sendRequest(request);
            }
        }
    };
    const credential = new DefaultAzureCredential(
        clientOptions,
    );
    const subscriptionId = "00000000-0000-0000-0000-000000000000";
    const client = new ContainerRegistryManagementClient(
        credential,
        subscriptionId,
        clientOptions,
    );
    console.log('list registries...');
    for await (const registry of client.registries.list()) {
        console.log(`registry: ${JSON.stringify(registry)}`);
    }
}

main();

The request object will be logged, indicating that the HttpsProxyAgent does not have port 8080 configured:

[...]
  agent: HttpsProxyAgent {
    [...]
    proxy: URL {
      href: 'http://proxy.example.com/',
      origin: 'http://proxy.example.com',
      protocol: 'http:',
      username: '',
      password: '',
      host: 'proxy.example.com',
      hostname: 'proxy.example.com',
      port: '',
      pathname: '/',
      search: '',
      searchParams: URLSearchParams {},
      hash: ''
    },
    proxyHeaders: {
      'content-type': 'application/x-www-form-urlencoded;charset=utf-8'
    },
    connectOpts: {
      ALPNProtocols: [Array],
      host: 'proxy.example.com',
      port: 80
    },
[...]

Expected behavior
HttpsProxyAgent has port 8080 configured:

[...]
  agent: HttpsProxyAgent {
    [...]
    proxy: {
      hostname: 'proxy.example.com',
      port: 8080,
      protocol: 'http:',
      headers: [Object],
      host: 'proxy.example.com'
    },
[...]
@github-actions github-actions bot added customer-reported Issues that are reported by GitHub users external to the Azure organization. needs-triage Workflow: This is a new issue that needs to be triaged to the appropriate team. question The issue doesn't require a change to the product in order to be resolved. Most issues start as that labels Mar 18, 2024
@timovv timovv added bug This issue requires a change to an existing behavior in the product in order to be resolved. Client This issue points to a problem in the data-plane of the library. Azure.Core and removed question The issue doesn't require a change to the product in order to be resolved. Most issues start as that labels Mar 18, 2024
@github-actions github-actions bot added needs-team-attention Workflow: This issue needs attention from Azure service team or SDK team and removed needs-triage Workflow: This is a new issue that needs to be triaged to the appropriate team. labels Mar 18, 2024
@xirzec xirzec self-assigned this Mar 19, 2024
@xirzec
Copy link
Member

xirzec commented Mar 19, 2024

@drizzd Thanks for the report! I have a PR out to address this and will work on getting it released soon.

xirzec added a commit that referenced this issue Mar 19, 2024
…red (#28974)

### Packages impacted by this PR

`@azure/core-rest-pipeline`

### Issues associated with this PR

#28951

### Describe the problem that is addressed by this PR

When PR #28563 upgraded `http-proxy-agent` it didn't properly pass along
`port` as this is now encoded in the proxy URL instead of the agent
options.

This PR trims down the unnecessary parsing we are doing to turn the
proxy URL into `ProxySettings`, preferring to pass the URL as-is to
`http-proxy-agent` and avoid losing information. In cases where we
receive `ProxySettings` we will convert it into a URL correctly.

For unknown historical reasons, `getDefaultProxySettings` was exposed as
public surface, but since we no longer need this internally, I have
marked it as deprecated so we may remove it in a later major version.

### Are there test cases added in this PR? _(If not, why?)_

Existing tests were updated to validate the proxy URL being set
correctly on the agent itself.
@xirzec
Copy link
Member

xirzec commented Mar 22, 2024

@drizzd this fix should be live now, please give it a try and let me know if you're still having issues.

@xirzec xirzec closed this as completed Mar 22, 2024
@drizzd
Copy link
Author

drizzd commented Apr 2, 2024

This works for me as of @azure/[email protected]. Thanks!

@github-actions github-actions bot locked and limited conversation to collaborators Jul 1, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Azure.Core bug This issue requires a change to an existing behavior in the product in order to be resolved. Client This issue points to a problem in the data-plane of the library. customer-reported Issues that are reported by GitHub users external to the Azure organization. needs-team-attention Workflow: This issue needs attention from Azure service team or SDK team
Projects
None yet
Development

No branches or pull requests

3 participants