HTTPClientRes is an http client resource. The Name will be used as the destination file path if the File param is not specified and if Name is in the shape of a valid absolute path. This resource will not redownload a file if it already exists and has the same mtime or sha256sum as we expect it to.
| 95 | // TODO: send/recv the http status too? |
| 96 | // TODO: add support for TLS |
| 97 | type HTTPClientRes struct { |
| 98 | traits.Base // add the base methods without re-implementation |
| 99 | traits.Edgeable // XXX: add autoedge support |
| 100 | traits.Refreshable |
| 101 | traits.Sendable |
| 102 | |
| 103 | init *engine.Init |
| 104 | |
| 105 | // File is the output destination to write to if we download a file. It |
| 106 | // must be an absolute file path. If you don't specify this, then the |
| 107 | // Name will be used if it's a valid absolute file path. If no valid |
| 108 | // file path exists anywhere, then we only download to a temporary |
| 109 | // directory. We always download to a temporary directory anyways so |
| 110 | // that we can atomically rename when we complete successfully. As a |
| 111 | // result, if you don't particularly want to store a file somewhere, |
| 112 | // then make sure the $name you specify does not resemble an absolute |
| 113 | // file path which would begin with a slash and end without one. |
| 114 | File string `lang:"file" yaml:"file"` |
| 115 | |
| 116 | // Method is the HTTP method (GET, POST, PUT, etc...) that is used. If |
| 117 | // you omit this then "GET" is used. |
| 118 | Method string `lang:"method" yaml:"method"` |
| 119 | |
| 120 | // URL is the endpoint to connect to. You may specify the protocol, |
| 121 | // username, password, port, and all the other variables. |
| 122 | URL string `lang:"url" yaml:"url"` |
| 123 | |
| 124 | // Body is the body to use when sending your request. It can be nil. |
| 125 | Body *string `lang:"body" yaml:"body"` |
| 126 | |
| 127 | // MtimeCheck specifies that we can attempt to avoid redownloading based |
| 128 | // on if the mtime that the server announces match what we already have |
| 129 | // on disk. |
| 130 | // TODO: what to name this? |
| 131 | MtimeCheck bool `lang:"mtime_check" yaml:"mtime_check"` |
| 132 | |
| 133 | // Sha256 is specified if you expect the file contents to have this |
| 134 | // hash. |
| 135 | Sha256 string `lang:"sha256" yaml:"sha256"` |
| 136 | |
| 137 | // Longpoll specifies that the server supports http long polling. If the |
| 138 | // endpoint actually does not, then this will cause infinite looping... |
| 139 | // if specifying this option you must also specify one of the types of |
| 140 | // long polling that you're using. This should match what the server |
| 141 | // expects as this is an arbitrary contract on top of HTTP and not an |
| 142 | // explicit part of the protocol. |
| 143 | Longpoll bool `lang:"longpoll" yaml:"longpoll"` |
| 144 | |
| 145 | // LongpollRedirect specifies that the server will use an HTTP redirect |
| 146 | // to notify you that the long poll is active and watching. |
| 147 | LongpollRedirect bool `lang:"longpoll_redirect" yaml:"longpoll_redirect"` |
| 148 | |
| 149 | // LongpollConditional specifies that the server will need a second HTTP |
| 150 | // request with a `Prefer: wait=<seconds>` header to set up the long |
| 151 | // polling. |
| 152 | // XXX: Can this method really guarantee the server started a watch? |
| 153 | LongpollConditional bool `lang:"longpoll_conditional" yaml:"longpoll_conditional"` |
| 154 |