Skip to content
This repository has been archived by the owner on Feb 27, 2023. It is now read-only.

Commit

Permalink
fix: use StringArrayVar to parse http header
Browse files Browse the repository at this point in the history
StringSliceVar will separated by comma, which is not suitable for field
like Date:Mon, 30 Dec 2019, use StringArrayVar instead

Signed-off-by: 慕陶 <jihui.xjh@antfin.com>
  • Loading branch information
慕陶 committed Jan 9, 2020
1 parent 7894da1 commit 7eb5be1
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion cmd/dfget/app/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ func initFlags() {
"filter some query params of URL, use char '&' to separate different params"+
"\neg: -f 'key&sign' will filter 'key' and 'sign' query param"+
"\nin this way, different but actually the same URLs can reuse the same downloading task")
flagSet.StringSliceVar(&cfg.Header, "header", nil,
flagSet.StringArrayVar(&cfg.Header, "header", nil,
"http header, eg: --header='Accept: *' --header='Host: abc'")
flagSet.VarP(config.NewSupernodesValue(&cfg.Supernodes, nil), "node", "n",
"specify the addresses(host:port=weight) of supernodes where the host is necessary, the port(default: 8002) and the weight(default:1) are optional. And the type of weight must be integer")
Expand Down
12 changes: 12 additions & 0 deletions cmd/dfget/app/root_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"github.com/dragonflyoss/Dragonfly/dfget/config"
"github.com/dragonflyoss/Dragonfly/pkg/errortypes"
"github.com/dragonflyoss/Dragonfly/pkg/rate"

"github.com/sirupsen/logrus"
"github.com/stretchr/testify/suite"
)
Expand Down Expand Up @@ -91,6 +92,17 @@ func (suit *dfgetSuit) Test_initProperties() {
}
}

func (suit *dfgetSuit) Test_HeaderFlags() {
originCfg := *cfg
defer func() {
cfg = &originCfg
}()
flagSet := rootCmd.Flags()
flagSet.Parse([]string{"--header", "Host: abc", "--header", "Date:Mon, 30 Dec 2019"})

suit.Equal(cfg.Header, []string{"Host: abc", "Date:Mon, 30 Dec 2019"})
}

func (suit *dfgetSuit) Test_transFilter() {
var cases = []string{
"a&b&c",
Expand Down

0 comments on commit 7eb5be1

Please sign in to comment.