@@ -174,17 +174,17 @@ func (httpOptions *HttpOptions) ExtractUrl() (string, error) {
174
174
}
175
175
}
176
176
177
- // If for an http-api command the agent-target address is a URL, it must be handled differently than dname and ip addresses
177
+ // If for an http-api command the agent-target address is a URL,
178
+ // we should warn for misuse of the field when appendind command-specified path
178
179
if len (target .Address ["url" ]) > 0 {
179
180
if target .Address ["url" ][0 ] != "" {
180
181
urlObject , err := parsePathBasedUrl (target .Address ["url" ][0 ])
181
182
if err != nil {
182
183
return "" , err
183
184
}
184
- if (urlObject .Path != "" && urlObject .Path != "/" ) && urlObject .Path ! = path {
185
- log .Warn ("agent-target url has path that does not match http-api command path" )
185
+ if (urlObject .Path != "" && urlObject .Path != "/" ) && urlObject .Path = = path {
186
+ log .Warn ("possible http api invocation path duplication: agent-target url has same path of http-api command path" )
186
187
}
187
- return urlObject .String (), nil
188
188
}
189
189
}
190
190
return buildSchemeAndHostname (path , target )
@@ -199,6 +199,20 @@ func buildSchemeAndHostname(path string, target *cacao.AgentTarget) (string, err
199
199
return "" , err
200
200
}
201
201
202
+ // If only URL is used to compose the URL target, then
203
+ // scheme and port are not considered
204
+ if len (target .Address ["url" ]) > 0 &&
205
+ len (target .Address ["dname" ]) == 0 &&
206
+ len (target .Address ["ipv4" ]) == 0 &&
207
+ len (target .Address ["ipv6" ]) == 0 {
208
+
209
+ url := strings .TrimSuffix (hostname , "/" )
210
+ if len (path ) > 1 && ! strings .HasPrefix (path , "/" ) {
211
+ path = "/" + path
212
+ }
213
+ return strings .TrimSuffix (url + path , "/" ), nil
214
+ }
215
+
202
216
parsedUrl := & url.URL {
203
217
Scheme : scheme ,
204
218
Host : fmt .Sprintf ("%s:%s" , hostname , target .Port ),
@@ -238,6 +252,13 @@ func extractHostname(target *cacao.AgentTarget) (string, error) {
238
252
}
239
253
address = target .Address ["ipv4" ][0 ]
240
254
255
+ } else if len (target .Address ["url" ]) > 0 {
256
+ _ , err := parsePathBasedUrl (target .Address ["url" ][0 ])
257
+ if err != nil {
258
+ return "" , err
259
+ }
260
+ address = target .Address ["url" ][0 ]
261
+
241
262
} else {
242
263
return "" , errors .New ("unsupported target address type" )
243
264
}
0 commit comments