Skip to content

Commit

Permalink
feat: add HTTP cookie header support (#223)
Browse files Browse the repository at this point in the history
* feat: add HTTP cookie header support

* Added docs, removed use of env var in client

* remove unused import
  • Loading branch information
oliwilkinsonio authored Aug 26, 2022
1 parent b545768 commit c508eeb
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 0 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,7 @@ Available configuration values:
- `skip-verify` - Disables data integrity verification when reading chunks to improve performance. Only recommended when chaining chunk stores with the `chunk-server` command using compressed stores.
- `uncompressed` - Reads and writes uncompressed chunks from/to this store. This can improve performance, especially for local stores or caches. Compressed and uncompressed chunks can coexist in the same store, but only one kind is read or written by one client.
- `http-auth` - Value of the Authorization header in HTTP requests. This could be a bearer token with `"Bearer <token>"` or a Base64-encoded username and password pair for basic authentication like `"Basic dXNlcjpwYXNzd29yZAo="`.
- `http-cookie` - Value of the Cookie header in HTTP requests. This should be in the form of a list of name-value pairs separated by a semicolon and a space (`'; '`) like `"name=value; name2=value2; name3=value3"`.

#### Example config

Expand Down Expand Up @@ -289,6 +290,9 @@ Available configuration values:
"https://example.com/*/*/": {
"http-auth": "Bearer dXNlcjpwYXNzd29yZA=="
},
"https://cdn.example.com/": {
"http-cookie": "PHPSESSID=298zf09hf012fh2; csrftoken=u32t4o3tb3gg43"
},
"/path/to/local/cache": {
"uncompressed": true
}
Expand Down
3 changes: 3 additions & 0 deletions remotehttp.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,9 @@ func (r *RemoteHTTPBase) IssueHttpRequest(method string, u *url.URL, getReader G
if r.opt.HTTPAuth != "" {
req.Header.Set("Authorization", r.opt.HTTPAuth)
}
if r.opt.HTTPCookie != "" {
req.Header.Set("Cookie", r.opt.HTTPCookie)
}

log.Debug("sending request")
resp, err = r.client.Do(req)
Expand Down
3 changes: 3 additions & 0 deletions store.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ type StoreOptions struct {
// Authorization header value for HTTP stores
HTTPAuth string `json:"http-auth,omitempty"`

// Cookie header value for HTTP stores
HTTPCookie string `json:"http-cookie,omitempty"`

// Timeout for waiting for objects to be retrieved. Infinite if negative. Default: 1 minute
Timeout time.Duration `json:"timeout,omitempty"`

Expand Down

0 comments on commit c508eeb

Please sign in to comment.