Skip to content

Custom Handler Proxying #11035

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

Open
wants to merge 22 commits into
base: dev
Choose a base branch
from
Open

Custom Handler Proxying #11035

wants to merge 22 commits into from

Conversation

satvu
Copy link
Member

@satvu satvu commented Apr 25, 2025

Issue describing the changes in this PR

resolves #11025

Pull request checklist

IMPORTANT: Currently, changes must be backported to the in-proc branch to be included in Core Tools and non-Flex deployments.

  • Backporting to the in-proc branch is not required
    • Otherwise: Link to backporting PR
  • My changes do not require documentation changes
    • Otherwise: Documentation issue linked to PR - TODO
  • My changes should not be added to the release notes for the next release
    • Otherwise: I've added my notes to release_notes.md
  • My changes do not need to be backported to a previous version
    • Otherwise: Backport tracked by issue/PR #issue_or_pr
  • My changes do not require diagnostic events changes
    • Otherwise: I have added/updated all related diagnostic events and their documentation (Documentation issue linked to PR)
  • I have added all required tests (Unit tests, E2E tests)

@satvu satvu marked this pull request as ready for review April 28, 2025 20:17
@satvu satvu requested a review from a team as a code owner April 28, 2025 20:17
@satvu satvu requested a review from fabiocav April 28, 2025 20:17
_httpProxyService.StartForwarding(scriptInvocationContext, _destinationPrefix);

await _httpProxyService.EnsureSuccessfulForwardingAsync(scriptInvocationContext);
scriptInvocationContext.ResultSource.SetResult(_successfulInvocationResult);
Copy link
Member

Choose a reason for hiding this comment

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

Does the downstream code updates this _successfulInvocationResult instance? I see we use a shared instance for all invocations.

Copy link
Member Author

Choose a reason for hiding this comment

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

No, the downstream code does not. This value is set to allow the function invocation to continue, but its value is never used (similar to how http proxying flows). We ignore the function invocation result at this step so that the actual response just flows through.

@satvu satvu requested review from kshyju and liliankasem April 29, 2025 23:19
@satvu satvu force-pushed the satvu/custom-handler-streaming branch from 6043724 to a05018b Compare May 14, 2025 00:46
};

_destinationPrefix = new UriBuilder(WorkerConstants.HttpScheme, WorkerConstants.HostName, _httpWorkerOptions.Port).Uri;
_userAgentString = $"{HttpWorkerConstants.UserAgentHeaderValue}/{ScriptHost.Version}";
Copy link
Member

Choose a reason for hiding this comment

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

Does this ever get set outside of the ctor? Could this be a const? It doesnt look like its made up of anything that would require it to be init in here no?

Copy link
Member Author

Choose a reason for hiding this comment

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

Doesn't get set outside of the ctor, but ScriptHost.Version isn't a constant so this can't be init as a constant outside of the ctor at the top of the file.

@satvu satvu requested a review from liliankasem June 9, 2025 22:51
@satvu satvu requested a review from fabiocav June 10, 2025 21:30
@@ -15,8 +15,16 @@ public class HttpWorkerOptions

public int Port { get; set; }

/// <summary>
/// Gets or sets a value indicating whether the host will rebuild the initial invocation HTTP Request and send the copy to the worker process.
/// </summary>
public bool EnableForwardingHttpRequest { get; set; }
Copy link
Member

Choose a reason for hiding this comment

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

A bit unclear about the property name and the summary comment. From the name, it sounds like the request is simply being forwarded as it is. But the comment suggests that a new copy of the request is being rebuilt from the original and that is sent to the worker process. Should we consider updating the property name to reflect that behavior?

Copy link
Member Author

@satvu satvu Jun 11, 2025

Choose a reason for hiding this comment

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

This is an existing property (see schema store) and we cannot change this without having breaking changes. It's also already documented.

This feature currently works by handling http requests here and calling this extension method.

It's a really unfortunate name - I believe the plan is to phase this setting out in favor of the new one (for streaming). I added the comments to try to make clear the difference between the two very similar property names.

@@ -47,6 +54,9 @@ internal DefaultHttpWorkerService(HttpClient httpClient, IOptions<HttpWorkerOpti
// Set 1 minute greater than FunctionTimeout to ensure invoction failure due to timeout is raised before httpClient raises operation cancelled exception
_httpClient.Timeout = scriptHostOptions.Value.FunctionTimeout.Value.Add(TimeSpan.FromMinutes(1));
}

_destinationPrefix = new UriBuilder(WorkerConstants.HttpScheme, WorkerConstants.HostName, _httpWorkerOptions.Port).Uri;
Copy link
Member

Choose a reason for hiding this comment

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

Is it a valid scenario where a customer configures their web app to only accept HTTPS traffic, but this code affects request forwarding because it explicitly uses HTTP? Should we allow the customer to specify or override the scheme?

Copy link
Member Author

Choose a reason for hiding this comment

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

I think your scenario could be valid - @fabiocav, is this an issue customers run into today? I borrowed from the existing pattern (for the EnableForwardingHttpRequest prop) in DefaultHttpWorkerService (see here) which only uses HTTP.

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.

Update custom handlers to proxy requests to custom workers
4 participants