isRemoteHTTPArchive checks if the source is a http/https url and is an archive It works by checking whether the source looks like a URL and, if it does, running a HEAD operation to see if the remote resource is a file that we understand.
(source string)
| 180 | // It works by checking whether the source looks like a URL and, if it does, running a |
| 181 | // HEAD operation to see if the remote resource is a file that we understand. |
| 182 | func isRemoteHTTPArchive(source string) bool { |
| 183 | if strings.HasPrefix(source, "http://") || strings.HasPrefix(source, "https://") { |
| 184 | // First, check if the URL ends with a known archive suffix |
| 185 | // This is more reliable than content-type detection |
| 186 | for suffix := range Extractors { |
| 187 | if strings.HasSuffix(source, suffix) { |
| 188 | return true |
| 189 | } |
| 190 | } |
| 191 | |
| 192 | // If no suffix match, try HEAD request to check content type |
| 193 | res, err := http.Head(source) |
| 194 | if err != nil { |
| 195 | // If we get an error at the network layer, we can't install it. So |
| 196 | // we return false. |
| 197 | return false |
| 198 | } |
| 199 | |
| 200 | // Next, we look for the content type or content disposition headers to see |
| 201 | // if they have matching extractors. |
| 202 | contentType := res.Header.Get("content-type") |
| 203 | foundSuffix, ok := mediaTypeToExtension(contentType) |
| 204 | if !ok { |
| 205 | // Media type not recognized |
| 206 | return false |
| 207 | } |
| 208 | |
| 209 | for suffix := range Extractors { |
| 210 | if strings.HasSuffix(foundSuffix, suffix) { |
| 211 | return true |
| 212 | } |
| 213 | } |
| 214 | } |
| 215 | return false |
| 216 | } |
| 217 | |
| 218 | // isPlugin checks if the directory contains a plugin.yaml file. |
| 219 | func isPlugin(dirname string) bool { |
searching dependent graphs…