Skip to content

Conversation

@nsrCodes
Copy link
Contributor

@nsrCodes nsrCodes commented Jul 31, 2024

  • sets the _originalUrl_ attribute on ctx
  • updates logger code to send port in case of local and non-http port

Does not need updated in desktop consumer or UI. Automatically shows port like this
Screenshot 2024-07-31 at 9 24 13 AM

fixes requestly/requestly#1971

Summary by CodeRabbit

  • Bug Fixes
    • Host resolution improved: request processing and generated logs/HAR now correctly preserve localhost, 127.0.0.1, 0.0.0.0 and custom ports.
    • Logging and capture now use refined host determination to avoid missing or incorrect host entries in captures and debug output.

- sets the _originalUrl_ attribute on ctx
- updates logger code to send port in case of local and non-http port
@nsrCodes nsrCodes requested a review from wrongsahil July 31, 2024 03:58
@CLAassistant
Copy link

CLAassistant commented Oct 6, 2025

CLA assistant check
All committers have signed the CLA.

@wrongsahil wrongsahil removed their request for review October 7, 2025 04:44
@wrongsahil wrongsahil self-requested a review October 29, 2025 09:01
@coderabbitai
Copy link

coderabbitai bot commented Oct 29, 2025

Walkthrough

Adds getHost(ctx) to src/components/proxy-middleware/rule_action_processor/utils.js, which derives the host string and appends a non-standard port when appropriate (considers protocol via ctx.isSSL, existing port in host, and localhost-like hosts). Updates src/components/proxy-middleware/middlewares/logger_middleware.js to import and use getHost(ctx) in the createHar call instead of ctx.rq.final_request.host, so HAR entries reflect ports when needed.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

  • Verify getHost(ctx) behavior: reads ctx.rq.final_request.host and port, determines protocol from ctx.isSSL, and appends :port only for non-standard ports when host lacks a port.
  • Confirm localhost detection covers localhost, 127.0.0.1, and 0.0.0.0 (or matches implementation).
  • Check logger_middleware.js imports getHost and passes its result into createHar.
  • Ensure HAR creation/logging is unchanged for hosts that already include ports or use standard ports.

Pre-merge checks and finishing touches

❌ Failed checks (2 warnings)
Check name Status Explanation Resolution
Title Check ⚠️ Warning The pull request title "feat: parse port from onConnect handler" specifically references an onConnect handler modification, but the provided raw summary shows no changes to any onConnect handler. Instead, the visible changes are the addition of a getHost utility function in utils.js and its integration into logger_middleware.js. While the PR objectives mention setting _originalUrl_ attribute and parsing port from onConnect handler, the raw summary provided does not document these specific changes, showing a disconnect between the title and the documented code changes. The title appears to reference implementation details not evident in the file summaries provided. The title should accurately reflect the actual code changes. Based on the raw summary, a more accurate title would be something like "feat: extract host with port in logger middleware" or "refactor: add getHost utility for consistent port handling in logs". The current title appears to reference onConnect handler changes that are not shown in the provided code summary and may mislead reviewers about what this PR actually modifies.
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Linked Issues Check ✅ Passed The linked issue #1971 requires the network interceptor table to display ports for localhost requests. The code changes address this by introducing a new getHost function that extracts the host and conditionally appends non-standard ports when appropriate (checking for both standard HTTP/HTTPS ports and whether a port already exists in the host). The logger middleware is updated to use this function, ensuring port information is now included in HAR creation and logging. The reviewer's checklist confirms various port scenarios have been tested and completed, indicating the implementation addresses the core requirement of showing ports for localhost and other hosts with custom ports.
Out of Scope Changes Check ✅ Passed The changes appear to be entirely in scope with respect to the linked issue. Both modifications—adding the getHost utility function and updating the logger middleware to use it—are directly aimed at including port information in logging output, which directly addresses issue #1971's requirement to display ports in the network interceptor table. No unrelated refactoring, feature additions, or changes outside the scope of port handling and logging are evident in the provided summary.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch ENGG-2087

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between dd578bb and 2d2bd22.

📒 Files selected for processing (1)
  • src/components/proxy-middleware/rule_action_processor/utils.js (1 hunks)

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/components/proxy-middleware/middlewares/logger_middleware.js (1)

79-90: Fix getHost() implementation to include port for all non-standard ports, not just localhost.

The change correctly uses getHost(ctx) in HAR generation, but this only partially solves the problem. The getHost() function at src/components/proxy-middleware/rule_action_processor/utils.js:48-55 has incomplete logic:

  • Returns with port for localhost-like hosts (localhost, 127.0.0.1, 0.0.0.0) when port exists
  • Returns without port for all other hosts, regardless of whether the port is non-standard

This causes:

  1. HAR URLs to be invalid for non-localhost hosts with non-standard ports (e.g., example.com:8080 becomes just example.com)
  2. curl generation via HTTPSnippet to lose port information for those scenarios
  3. Network interceptor UI to display incomplete host information

Update getHost() to include port information for all non-standard ports (not just localhost), or document this as a known limitation.

🧹 Nitpick comments (1)
src/components/proxy-middleware/rule_action_processor/utils.js (1)

44-46: Consider adding IPv6 localhost support.

The function currently checks for IPv4 localhost variants but doesn't include ::1 (IPv6 localhost). Depending on your use case, this might cause ports not to display for IPv6 localhost requests.

Apply this diff to add IPv6 support:

 function isLocalHost(host) {
-  return host === "localhost" || host === "127.0.0.1" || host === "0.0.0.0";
+  return host === "localhost" || host === "127.0.0.1" || host === "0.0.0.0" || host === "::1";
 }
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d59835c and 1b663c4.

📒 Files selected for processing (2)
  • src/components/proxy-middleware/middlewares/logger_middleware.js (3 hunks)
  • src/components/proxy-middleware/rule_action_processor/utils.js (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
src/components/proxy-middleware/middlewares/logger_middleware.js (1)
src/components/proxy-middleware/rule_action_processor/utils.js (2)
  • getHost (48-55)
  • getHost (48-55)
🔇 Additional comments (2)
src/components/proxy-middleware/middlewares/logger_middleware.js (2)

3-3: LGTM!

The import statement correctly adds getHost from the utils module.


24-24: Improve error handling and investigate HTTPSnippet conversion failure for localhost requests.

The code correctly uses getHost(ctx) (line 83) which includes the port for localhost URLs. However, the comment indicates HTTPSnippet conversion consistently fails despite this. The error is silently caught and only logged to console without capturing details.

  • Enhance error logging to capture and preserve the actual error message instead of just stringifying it
  • Investigate why HTTPSnippet fails even with properly formatted localhost URLs (e.g., http://localhost:8080/path)
  • Consider whether this is a known HTTPSnippet limitation with localhost or if there's a malformed HAR structure issue
  • Consider whether the generated curl should gracefully degrade or if the error should be surfaced differently

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

♻️ Duplicate comments (1)
src/components/proxy-middleware/rule_action_processor/utils.js (1)

50-57: Incomplete port display logic - non-localhost hosts with non-standard ports won't be handled.

The current implementation only appends the port for localhost-like hosts. However, the PR description mentions "local and non-HTTP ports," suggesting ports should be displayed for any host with non-standard ports (e.g., example.com:8080, 192.168.1.1:3000).

Additionally, this logic doesn't handle these edge cases:

  1. Duplicate ports: If ctx.rq.final_request.host already contains a port (e.g., "localhost:3000"), this would result in "localhost:3000:3000".
  2. Standard ports: Ports 80 (HTTP) and 443 (HTTPS) typically shouldn't be displayed.
  3. Port validation: No check if port is undefined or already included in the host.

Consider refactoring to handle all hosts with non-standard ports:

 export const getHost = (ctx) => {
   const finalHost = ctx.rq.final_request.host;
-  if(isLocalHost(finalHost) && ctx.rq.final_request.port) {
-    return `${finalHost}:${ctx.rq.final_request.port}`;
-  } else {
-    return finalHost
-  }
+  const port = ctx.rq.final_request.port;
+  const protocol = ctx.isSSL ? "https" : "http";
+  const standardPort = protocol === "https" ? 443 : 80;
+  
+  // Strip existing port from host to avoid duplicates
+  const hostWithoutPort = finalHost.split(':')[0];
+  
+  // Only append port if it's non-standard and present
+  if (port && port !== standardPort) {
+    return `${hostWithoutPort}:${port}`;
+  }
+  return hostWithoutPort;
 }
🧹 Nitpick comments (1)
src/components/proxy-middleware/rule_action_processor/utils.js (1)

46-48: Add IPv6 localhost support.

The isLocalHost function only checks for IPv4 localhost variations but misses IPv6 localhost (::1). This could cause ports to not display for IPv6 localhost requests.

Apply this diff to add IPv6 support:

 function isLocalHost(host) {
-  return host === "localhost" || host === "127.0.0.1" || host === "0.0.0.0";
+  return host === "localhost" || host === "127.0.0.1" || host === "0.0.0.0" || host === "::1";
 }
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 1b663c4 and 3dcb935.

📒 Files selected for processing (2)
  • src/components/proxy-middleware/middlewares/logger_middleware.js (3 hunks)
  • src/components/proxy-middleware/rule_action_processor/utils.js (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
src/components/proxy-middleware/middlewares/logger_middleware.js (1)
src/components/proxy-middleware/rule_action_processor/utils.js (2)
  • getHost (50-57)
  • getHost (50-57)
🪛 Biome (2.1.2)
src/components/proxy-middleware/rule_action_processor/utils.js

[error] 49-57: Illegal use of an export declaration outside of a module

not allowed inside scripts

(parse)

src/components/proxy-middleware/middlewares/logger_middleware.js

[error] 3-4: Illegal use of an import declaration outside of a module

not allowed inside scripts

(parse)

🔇 Additional comments (1)
src/components/proxy-middleware/middlewares/logger_middleware.js (1)

1-4: LGTM - Clean integration of the new utility.

The import of getHost is correctly added and follows the existing import pattern.

@wrongsahil
Copy link
Member

wrongsahil commented Oct 29, 2025

Cases

  • Localhost with custom ports (e.g., localhost:3000)
  • Non-localhost hosts with custom ports (e.g., example.com:8080)
  • IPv4 addresses with ports (e.g., 192.168.1.1:3000)
  • Non ssl endpoint http://example1.com
  • SSL endpoint https://requestly.com
  • IPv4, Any host, localhost with standard port. Eg: 192.168.1.1:80

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3dcb935 and dd578bb.

📒 Files selected for processing (1)
  • src/components/proxy-middleware/rule_action_processor/utils.js (1 hunks)
🧰 Additional context used
🪛 Biome (2.1.2)
src/components/proxy-middleware/rule_action_processor/utils.js

[error] 49-62: Illegal use of an export declaration outside of a module

not allowed inside scripts

(parse)

@wrongsahil wrongsahil merged commit 2c8dfae into master Oct 29, 2025
2 checks passed
@wrongsahil wrongsahil deleted the ENGG-2087 branch October 29, 2025 10:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: network interceptor table not showing ports for localhost

4 participants