-
Notifications
You must be signed in to change notification settings - Fork 580
refactor(server): unify URL configs when scheme is missing #2944
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
Changes from 1 commit
85dc7db
8dff246
575a642
a1b42cd
20d9cf2
f3b01e7
67a0c9d
358d037
09c4fc0
d1de457
fb5459c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -88,8 +88,12 @@ private void setLayoutIfNeeded(Configuration conf) { | |||||||||||||||||||||||||||||||||||
| public <T, R> R get(TypedOption<T, R> option) { | ||||||||||||||||||||||||||||||||||||
| Object value = this.getProperty(option.name()); | ||||||||||||||||||||||||||||||||||||
| if (value == null) { | ||||||||||||||||||||||||||||||||||||
| return option.defaultValue(); | ||||||||||||||||||||||||||||||||||||
| value = option.defaultValue(); | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| // Normalize URL options if needed (add scheme like http://) | ||||||||||||||||||||||||||||||||||||
| value = normalizeUrlOptionIfNeeded(option.name(), value); | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| return (R) value; | ||||||||||||||||||||||||||||||||||||
|
Comment on lines
91
to
104
|
||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
|
|
@@ -213,4 +217,55 @@ private static Configuration loadConfigFile(File configFile) { | |||||||||||||||||||||||||||||||||||
| e, configFile); | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| private static Object normalizeUrlOptionIfNeeded(String key, Object value) { | ||||||||||||||||||||||||||||||||||||
| if (value == null) { | ||||||||||||||||||||||||||||||||||||
| return null; | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
bitflicker64 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| String scheme = defaultSchemeFor(key); | ||||||||||||||||||||||||||||||||||||
| if (scheme == null) { | ||||||||||||||||||||||||||||||||||||
| return value; | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| // URL options are defined as ConfigOption<String> and normalized here. | ||||||||||||||||||||||||||||||||||||
bitflicker64 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||||||||||||||||||||||||||||||||
| if (value instanceof String) { | ||||||||||||||||||||||||||||||||||||
| return prefixSchemeIfMissing((String) value, scheme); | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| // If it ever hits here, it means config storage returned a non-string type; | ||||||||||||||||||||||||||||||||||||
| // leave it unchanged (safer than forcing toString()). | ||||||||||||||||||||||||||||||||||||
| return value; | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| private static String defaultSchemeFor(String key) { | ||||||||||||||||||||||||||||||||||||
bitflicker64 marked this conversation as resolved.
Show resolved
Hide resolved
bitflicker64 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||||||||||||||||
| switch (key) { | ||||||||||||||||||||||||||||||||||||
| case "restserver.url": | ||||||||||||||||||||||||||||||||||||
| case "gremlinserver.url": | ||||||||||||||||||||||||||||||||||||
| case "server.urls_to_pd": | ||||||||||||||||||||||||||||||||||||
| return "http://"; | ||||||||||||||||||||||||||||||||||||
| case "server.k8s_url": | ||||||||||||||||||||||||||||||||||||
| return "https://"; | ||||||||||||||||||||||||||||||||||||
| default: | ||||||||||||||||||||||||||||||||||||
| return null; | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| private static String prefixSchemeIfMissing(String raw, String scheme) { | ||||||||||||||||||||||||||||||||||||
| if (raw == null) { | ||||||||||||||||||||||||||||||||||||
| return null; | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
| String s = raw.trim(); | ||||||||||||||||||||||||||||||||||||
| if (s.isEmpty()) { | ||||||||||||||||||||||||||||||||||||
| return s; | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| // Keep original string if scheme already exists | ||||||||||||||||||||||||||||||||||||
bitflicker64 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||||||||||||||||||||||||||||||||
| String lower = s.toLowerCase(); | ||||||||||||||||||||||||||||||||||||
| if (lower.startsWith("http://") || lower.startsWith("https://")) { | ||||||||||||||||||||||||||||||||||||
| return s; | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The current implementation doesn't handle URLs with credentials or userinfo: // These would incorrectly get prefixed:
"user:password@127.0.0.1:8080" → "http://user:password@127.0.0.1:8080"
"admin@localhost:8080" → "http://admin@localhost:8080"While valid according to RFC 3986 (
Suggested change
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The prefixSchemeIfMissing() method currently just normalizes URLs and doesn’t try to validate things like userinfo (user@host). That seems reasonable since handling credentials in URLs is discouraged and @ can also appear in valid paths. Adding special checks here would blur the line between normalization and validation.It’s probably better to handle stricter validation at the client/usage layer if needed.I’m happy to add a separate check or open an additional PR if you think stricter handling belongs here. Please let me know your preference. |
||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| return scheme + s; | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
Uh oh!
There was an error while loading. Please reload this page.