[FHIR Connector] Add a general proxy function to forward requests to FHIR server with url rewrite#55
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review infoConfiguration used: Organization UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughAdded a public Changes
Sequence Diagram(s)sequenceDiagram
participant Client as Client
participant Connector as FHIRConnector
participant HTTPClient as HTTP Client
participant FHIRServer as FHIR Server
Client->>Connector: proxy(requestUrl, request)
Note over Connector: Log incoming request URL
Connector->>Connector: Enrich headers (add PKJWT if configured)
Connector->>HTTPClient: forward(requestUrl, enriched request)
HTTPClient->>FHIRServer: Forwarded HTTP request
FHIRServer-->>HTTPClient: Upstream response
HTTPClient-->>Connector: Return response
Note over Connector: Optionally call generalRewriteServerUrl to rewrite URLs
Connector-->>Client: Return http:Response or FHIRError
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@fhir/fhir_connector.bal`:
- Line 991: Update the `@return` doc comment for the FHIRResponse to remove the
contradiction by rephrasing it to something like "The upstream FHIRResponse,
with URL rewriting applied when enabled." Locate the `@return` entry in the doc
comment block that references FHIRResponse in fhir_connector.bal (the line
containing "@return - The upstream FHIRResponse as-is (with URL rewriting
applied when enabled)") and replace that text so it clearly states the response
may be rewritten when enabled.
- Around line 997-1002: The code currently assigns the result of
self.httpClient->forward(...) directly to a FHIRResponse, which bypasses
parsing; change the flow to call getFhirResourceResponse() with the
http:Response returned by self.httpClient->forward(enrichRequest(...)) so the
http response is converted into a proper FHIRResponse (preserving
httpStatusCode, resource, and serverResponseHeaders), then pass that parsed
FHIRResponse into rewriteServerUrl(...) when self.urlRewrite is true and return
the parsed/possibly-rewritten FHIRResponse; also update the method docstring to
remove the "as-is" phrasing and note that URL rewriting may be applied.
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@fhir/fhir_connector.bal`:
- Line 987: Update the function-level summary that currently reads "Proxies an
incoming HTTP request to the FHIR server and returns the upstream response
as-is" to accurately reflect that URL rewriting may be applied when
self.urlRewrite is true; find the function whose docstring contains that
sentence (the method handling the incoming HTTP proxy and referencing
self.urlRewrite) and change the summary to something like "Proxies an incoming
HTTP request to the FHIR server and returns the upstream response (URLs may be
rewritten when self.urlRewrite is true)" so the description no longer claims the
response is returned "as-is."
In `@fhir/utils.bal`:
- Around line 608-610: The current isolated function rewrite uses re
`${baseUrl}` which treats baseUrl as a regex and causes false-positive matches;
implement a fix by creating a utility to escape regex metacharacters in baseUrl
(or alternatively reconstruct the URL and replace parts without regex), then use
the escaped string when building the regex pattern or use a literal string
replacement routine; update the rewrite function (and the other occurrence where
baseUrl is interpolated into a regex) to call that escape utility (or use the
non-regex replacement approach) and then perform the replace so matches are
exact for replacementUrl.
$subject
This pull request adds a general-purpose proxy facility to the FHIR connector to forward incoming HTTP requests to a configured FHIR server, with optional URL rewriting, consistent error handling, and improved observability.
Changes
Behavior and outcomes
Other notes