Skip to content

Commit

Permalink
Added content disposition header support
Browse files Browse the repository at this point in the history
  • Loading branch information
ishanjain28 committed Sep 11, 2017
1 parent a485a5c commit c528769
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
23 changes: 21 additions & 2 deletions pluto/pluto.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"net/http"
"net/url"
"runtime"
"strings"
"sync"
"time"
)
Expand Down Expand Up @@ -203,7 +204,7 @@ func FetchMeta(u *url.URL) (*FileMeta, error) {
}
defer resp.Body.Close()

if resp.StatusCode != 200 && resp.StatusCode != 206 {
if resp.StatusCode != http.StatusOK && resp.StatusCode != http.StatusPartialContent {
return nil, fmt.Errorf("status code is %d", resp.StatusCode)
}

Expand All @@ -218,7 +219,25 @@ func FetchMeta(u *url.URL) (*FileMeta, error) {
m = false
}

return &FileMeta{Size: uint64(size), u: u, MultipartSupported: m}, nil
resp, err = http.Get(u.String())
if err != nil {
return nil, fmt.Errorf("error in sending GET request: %v", err)
}

cDispose := strings.Split(resp.Header.Get("Content-Disposition"), "filename=")

name := ""

if len(cDispose) > 0 {
cdfilename := cDispose[1]
cdfilename = cdfilename[1:]
cdfilename = cdfilename[:len(cdfilename)-1]
name = cdfilename
}

resp.Body.Close()

return &FileMeta{Size: uint64(size), Name: name, u: u, MultipartSupported: m}, nil
}

func download(begin, end uint64, u *url.URL) (io.ReadCloser, error) {
Expand Down
5 changes: 4 additions & 1 deletion pluto_cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,15 @@ func download(u, filename string, parts uint, verbose bool) {
return
}

meta.Name = filename
if filename != "" {
meta.Name = filename
}

if meta.Name == "" {
meta.Name = fname
}

fmt.Println(meta.Name)
saveFile, err := os.Create(meta.Name)
if err != nil {
errored = true
Expand Down

0 comments on commit c528769

Please sign in to comment.