Skip to content

Extend swift-configuration support to proxy configuration#904

Open
hamzahrmalik wants to merge 2 commits into
swift-server:mainfrom
hamzahrmalik:swift_config_proxy
Open

Extend swift-configuration support to proxy configuration#904
hamzahrmalik wants to merge 2 commits into
swift-server:mainfrom
hamzahrmalik:swift_config_proxy

Conversation

@hamzahrmalik
Copy link
Copy Markdown
Contributor

Extending #878 to also allow configuring the proxy via ConfigReader

Copy link
Copy Markdown
Contributor

@aryan-25 aryan-25 left a comment

Choose a reason for hiding this comment

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

LGTM, just one nit.

/// Only supported for `http` proxies.
///
/// - Throws: `HTTPClientError.invalidProxyConfiguration` if `enabled` is `true` but `host` is missing, `type` is unknown,
/// `port` is missing for an HTTP proxy, or authorization is specified for a SOCKS proxy.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit:

Suggested change
/// `port` is missing for an HTTP proxy, or authorization is specified for a SOCKS proxy.
/// `port` is missing for an HTTP proxy, or `authorization` is specified for a SOCKS proxy.

Also, I know the HTTPClient.Authorization config init has this documented, but it might be worth calling out here that this error is also thrown when the provided authorization for an HTTP proxy is invalid.

guard configReader.bool(forKey: "enabled", default: false) else {
return nil
}
guard let host = configReader.string(forKey: "host") else {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Are you deliberately not using requiredString(forKey:) so that you can thrown an HTTPClientError? (Ignore me if I'm misremembering the API.)

Minor concern is that invalidProxyConfiguration doesn't tell you what you got wrong, only that you got something wrong. I assume the swift-configuration error would tell you what required key was missing.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

there's no precedent within this file, because we dont have any required props until now

There is invalidHTTPVersionConfiguration and invalidDNSOverridesConfiguration but these are for invalid values rather than missing values.

I think youre right and using the requiredString etc functions makes more sense

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

you do still need the custom error for Authentication though, since we need one of several keys to exist

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.

3 participants