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

Download URLs do not work with a proxy server in front #7

Open
bbrendon opened this issue Jul 11, 2024 · 2 comments
Open

Download URLs do not work with a proxy server in front #7

bbrendon opened this issue Jul 11, 2024 · 2 comments
Labels
priority: P2 Smaller impact or easy workaround type: enhancement New feature or request
Milestone

Comments

@bbrendon
Copy link

bbrendon commented Jul 11, 2024

I spun this up and have haproxy forwarding to express. The SSL is on HAproxy, and express is running as http.

I added the haproxy URL using https as source to choco.

I get back :

...
Installing the following packages:
openssl
By installing, you accept licenses for the packages.
Downloading package from source 'https://url.com/'
[NuGet] Error downloading 'chocolatey-windowsupdate.extension.1.0.5' from 'http://url.com/download/chocolatey-windowsupdate.extension'.
[NuGet] An error occurred while sending the request.

Notice above the https is missing from the nuget line?

Any solutions?

I'm going to attempt an HTTP -> HTTPS redirect but that isn't the best solution.

@joeyparrish
Copy link
Member

Is chocolatey constructing that plain HTTP URL, or is the server constructing a plain HTTP URL in response to some HTTPS request?

@joeyparrish
Copy link
Member

This could be relevant:

// If we have a buffer for the nupkg file, add a URL that points back to
// this server to download it. Applications can also provide an explicit,
// off-site URL. {EXPRESS_URL_ROOT} will be replaced by the root of the
// request right before serving the response, so that responses can contain
// absolute URLs without preconfiguring the server with its own address.
if (entry.nupkgData) {
entry.url = `{EXPRESS_URL_ROOT}${prefix}download/${entry.id}`;
}

And this:

function formatPackages(matchedPackages, req) {
const entries = matchedPackages.map((entry) => {
return entryTemplate.replace(/{(.*)}/g, (match, key) => xmlescape(entry[key]) || '');
});
const url_root = req.protocol + '://' + req.get('host');
return packagesTemplate
.replace(/{entries}\n/g, entries.join(''))
.replace(/{EXPRESS_URL_ROOT}/, url_root);
}

I think this explains it. This server will construct absolute URLs based on the request, which is the plain HTTP request forwarded from HAProxy.

This zero-config scheme I built doesn't work with a proxy, since the underlying server can't know the address of the proxy.

I think you would need to add some config to supply the URL root when using a proxy.

I suggest you send a PR that:

  1. Adds a URL root parameter to configureRoutes. If null/undefined, the existing behavior is used where we deduce the URL root from the incoming request in formatPackages.
  2. Add a parameter parser (we use yargs in our other JS projects) and a command-line argument in cli.js to supply this config to configureRoutes.
  3. Add an example of this to the "Standalone server" section of README.md

@joeyparrish joeyparrish added type: enhancement New feature or request priority: P2 Smaller impact or easy workaround labels Jul 31, 2024
@joeyparrish joeyparrish changed the title URLs are http instead of https Download URLs do not work with a proxy server in front Jul 31, 2024
@github-actions github-actions bot added this to the Backlog milestone Jul 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
priority: P2 Smaller impact or easy workaround type: enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants