Skip to content

🐛 Fix default proxy port#413

Merged
wwilsman merged 3 commits intomasterfrom
ww/fix-default-proxy-port
Jul 15, 2021
Merged

🐛 Fix default proxy port#413
wwilsman merged 3 commits intomasterfrom
ww/fix-default-proxy-port

Conversation

@wwilsman
Copy link
Copy Markdown
Contributor

@wwilsman wwilsman commented Jul 14, 2021

What is this?

With new URL(), the default port is never included in the resulting object, even when explicitly defined.

new URL('http://localhost:80').port
// => ""

new URL('https://localhost:443').port
// => ""

In the @percy/client proxy, the proxy address' port is passed along to the (net|tls).connect method. With the above in mind, this results in an empty string being passed along. Since the port option is a required argument of the method, this causes connections to immediately close, showing only a vague error.

This PR adds a small port util which will return a default port if one isn't specified, port 443 for HTTPS requests or port 80 otherwise. This util is then used in the two places where a URL port is referenced.

Fixes #402

@wwilsman wwilsman added the 🐛 bug Something isn't working label Jul 14, 2021
@wwilsman wwilsman requested a review from Robdel12 July 14, 2021 20:05
@wwilsman
Copy link
Copy Markdown
Contributor Author

Locally, the tests pass since I can freely bind to ports 80 and 443. In CI however, those ports are restricted. I might be able to use sudo for linux, but I'm still looking into a workaround for windows (or a GH actions config for either).

@wwilsman wwilsman force-pushed the ww/fix-default-proxy-port branch from 36965fc to ce0cfed Compare July 14, 2021 21:33
@wwilsman wwilsman force-pushed the ww/fix-default-proxy-port branch from c00472e to 3bdf231 Compare July 14, 2021 21:42
@wwilsman
Copy link
Copy Markdown
Contributor Author

Rather than elevate privileges in CI, which felt wrong and proved to be rather difficult without moving to self-hosted containers, I opted to adjust the tests to allow server creation and request failures while still testing for a default port using a jasmine spy. With the adjustments, coverage dropped and so a rewritten test was added back to take care of it.

Copy link
Copy Markdown
Contributor

@Robdel12 Robdel12 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🏁

@wwilsman wwilsman merged commit 141e656 into master Jul 15, 2021
@wwilsman wwilsman deleted the ww/fix-default-proxy-port branch July 15, 2021 15:32
samarsault pushed a commit that referenced this pull request Mar 3, 2023
Bumps [@percy/core](https://github.com/percy/cli/tree/HEAD/packages/core) from 1.0.0-beta.67 to 1.0.0-beta.68.
- [Release notes](https://github.com/percy/cli/releases)
- [Commits](https://github.com/percy/cli/commits/v1.0.0-beta.68/packages/core)

---
updated-dependencies:
- dependency-name: "@percy/core"
  dependency-type: direct:development
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🐛 bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Proxy: Port 80 is stripped from URL

2 participants