Skip to content

Commit aca6196

Browse files
authored
Merge pull request #14 from ncw/range
files: Allow extra headers for file download in DownloadHeaders
2 parents 38a9910 + 67b51e1 commit aca6196

File tree

4 files changed

+15
-3
lines changed

4 files changed

+15
-3
lines changed

dropbox/files/client.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1331,6 +1331,9 @@ func (dbx *apiImpl) Download(arg *DownloadArg) (res *FileMetadata, content io.Re
13311331
headers := map[string]string{
13321332
"Dropbox-API-Arg": string(b),
13331333
}
1334+
for k, v := range arg.ExtraHeaders {
1335+
headers[k] = v
1336+
}
13341337
if dbx.Config.AsMemberID != "" {
13351338
headers["Dropbox-API-Select-User"] = dbx.Config.AsMemberID
13361339
}
@@ -1350,7 +1353,7 @@ func (dbx *apiImpl) Download(arg *DownloadArg) (res *FileMetadata, content io.Re
13501353
body := []byte(resp.Header.Get("Dropbox-API-Result"))
13511354
content = resp.Body
13521355
dbx.Config.TryLog("body: %v", body)
1353-
if resp.StatusCode == http.StatusOK {
1356+
if resp.StatusCode == http.StatusOK || resp.StatusCode == http.StatusPartialContent {
13541357
err = json.Unmarshal(body, &res)
13551358
if err != nil {
13561359
return

dropbox/files/types.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -739,6 +739,8 @@ type DownloadArg struct {
739739
Path string `json:"path"`
740740
// Rev : Deprecated. Please specify revision in `path` instead.
741741
Rev string `json:"rev,omitempty"`
742+
// ExtraHeaders can be used to pass Range, If-None-Match headers
743+
ExtraHeaders map[string]string `json:"-"`
742744
}
743745

744746
// NewDownloadArg returns a new DownloadArg instance

generator/go_client.stoneg.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,10 @@ def _generate_route(self, namespace, route):
9090
self._generate_request(namespace, route)
9191
self._generate_post()
9292
self._generate_response(route)
93-
with self.block('if resp.StatusCode == http.StatusOK'):
93+
ok_check = 'if resp.StatusCode == http.StatusOK'
94+
if fn == "Download":
95+
ok_check += ' || resp.StatusCode == http.StatusPartialContent'
96+
with self.block(ok_check):
9497
self._generate_result(route)
9598
self._generate_error_handling(route)
9699

@@ -128,6 +131,8 @@ def _generate_request(self, namespace, route):
128131
for k, v in sorted(headers.items()):
129132
out('\t"{}": {},'.format(k, v))
130133
out('}')
134+
if fmt_var(route.name) == "Download":
135+
out('for k, v := range arg.ExtraHeaders { headers[k] = v }')
131136
if auth != 'noauth' and auth != 'team':
132137
with self.block('if dbx.Config.AsMemberID != ""'):
133138
out('headers["Dropbox-API-Select-User"] = dbx.Config.AsMemberID')

generator/go_types.stoneg.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,9 @@ def _generate_struct(self, struct):
8686
self.emit(fmt_type(struct.parent_type, struct.namespace).lstrip('*'))
8787
for field in struct.fields:
8888
self._generate_field(field, namespace=struct.namespace)
89-
self.emit()
89+
if struct.name in ('DownloadArg',):
90+
self.emit('// ExtraHeaders can be used to pass Range, If-None-Match headers')
91+
self.emit('ExtraHeaders map[string]string `json:"-"`')
9092
self._generate_struct_builder(struct)
9193

9294
def _generate_struct_builder(self, struct):

0 commit comments

Comments
 (0)