-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature/custom headers and cookies (#20)
* user-specified headers and cookies * actions update * go version up
- Loading branch information
Showing
20 changed files
with
520 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,20 +16,20 @@ jobs: | |
name: ci | ||
steps: | ||
- name: checkout | ||
uses: actions/checkout@v2 | ||
uses: actions/checkout@v3 | ||
- name: golangci-lint | ||
uses: golangci/golangci-lint-action@v2 | ||
uses: golangci/golangci-lint-action@v3 | ||
test: | ||
runs-on: ubuntu-latest | ||
environment: | ||
name: ci | ||
steps: | ||
- name: checkout | ||
uses: actions/checkout@v2 | ||
uses: actions/checkout@v3 | ||
- name: setup golang | ||
uses: actions/setup-go@v2 | ||
uses: actions/setup-go@v3 | ||
with: | ||
go-version: ^1.17 | ||
go-version: ^1.18 | ||
- name: test-coverage | ||
uses: paambaati/[email protected] | ||
env: | ||
|
@@ -44,14 +44,14 @@ jobs: | |
name: ci | ||
steps: | ||
- name: checkout | ||
uses: actions/checkout@v2 | ||
uses: actions/checkout@v3 | ||
- name: setup golang | ||
uses: actions/setup-go@v2 | ||
uses: actions/setup-go@v3 | ||
with: | ||
go-version: ^1.17 | ||
go-version: ^1.18 | ||
- name: init codeql | ||
uses: github/codeql-action/init@v1 | ||
uses: github/codeql-action/init@v2 | ||
with: | ||
language: 'go' | ||
- name: run analysis | ||
uses: github/codeql-action/analyze@v1 | ||
uses: github/codeql-action/analyze@v2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
module github.com/s0rg/crawley | ||
|
||
go 1.17 | ||
go 1.18 | ||
|
||
require golang.org/x/net v0.0.0-20211216030914-fe4d6282115f | ||
require golang.org/x/net v0.0.0-20220607020251-c690dde0001d |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,2 @@ | ||
golang.org/x/net v0.0.0-20211216030914-fe4d6282115f h1:hEYJvxw1lSnWIl8X9ofsYMklzaDs90JI2az5YMd4fPM= | ||
golang.org/x/net v0.0.0-20211216030914-fe4d6282115f/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= | ||
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= | ||
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= | ||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= | ||
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= | ||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= | ||
golang.org/x/net v0.0.0-20220607020251-c690dde0001d h1:4SFsTMi4UahlKoloni7L4eYzhFRifURQLw+yv0QDCx8= | ||
golang.org/x/net v0.0.0-20220607020251-c690dde0001d/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package client | ||
|
||
import ( | ||
"net/http" | ||
"strings" | ||
) | ||
|
||
const ( | ||
keyvalParts = 2 | ||
keyvalSeparator = "=" | ||
valuesSeparator = ";" | ||
) | ||
|
||
func prepareCookies(raw []string) (rv []*http.Cookie) { | ||
for _, r := range raw { | ||
for _, p := range strings.Split(r, valuesSeparator) { | ||
if val, ok := parseOne(p); ok { | ||
rv = append(rv, val) | ||
} | ||
} | ||
} | ||
|
||
return rv | ||
} | ||
|
||
func parseOne(raw string) (rv *http.Cookie, ok bool) { | ||
pair := strings.SplitN(raw, keyvalSeparator, keyvalParts) | ||
|
||
var name, value string | ||
|
||
if name = strings.TrimSpace(pair[0]); name == "" { | ||
return | ||
} | ||
|
||
if value = strings.TrimSpace(pair[1]); value == "" { | ||
return | ||
} | ||
|
||
rv = &http.Cookie{ | ||
Name: name, | ||
Value: value, | ||
} | ||
|
||
return rv, true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package client | ||
|
||
import ( | ||
"net/http" | ||
"reflect" | ||
"testing" | ||
) | ||
|
||
func Test_prepareCookies(t *testing.T) { | ||
t.Parallel() | ||
|
||
tests := []struct { | ||
name string | ||
args []string | ||
want []*http.Cookie | ||
}{ | ||
{"1", | ||
[]string{"NAME1=VALUE1; NAME2=VALUE2", "NAME3=VALUE3"}, | ||
[]*http.Cookie{ | ||
{Name: "NAME1", Value: "VALUE1"}, | ||
{Name: "NAME2", Value: "VALUE2"}, | ||
{Name: "NAME3", Value: "VALUE3"}, | ||
}}, | ||
{"2", | ||
[]string{"", "NAME=", "=VALUE", ";;", "===", " VALID = COOKIE "}, | ||
[]*http.Cookie{ | ||
{Name: "VALID", Value: "COOKIE"}, | ||
}}, | ||
} | ||
|
||
for _, tt := range tests { | ||
if got := prepareCookies(tt.args); !reflect.DeepEqual(got, tt.want) { | ||
t.Errorf("prepareCookies() = %v, want %v", got, tt.want) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package client | ||
|
||
import "strings" | ||
|
||
const ( | ||
headerParts = 2 | ||
headerSeparator = ":" | ||
) | ||
|
||
type header struct { | ||
Key string | ||
Val string | ||
} | ||
|
||
func prepareHeaders(raw []string) (rv []*header) { | ||
rv = make([]*header, 0, len(raw)) | ||
|
||
var ( | ||
pair []string | ||
key, val string | ||
) | ||
|
||
for _, h := range raw { | ||
pair = strings.SplitN(h, headerSeparator, headerParts) | ||
|
||
if key = strings.TrimSpace(pair[0]); key == "" { | ||
continue | ||
} | ||
|
||
if val = strings.TrimSpace(pair[1]); val == "" { | ||
continue | ||
} | ||
|
||
rv = append(rv, &header{Key: key, Val: val}) | ||
} | ||
|
||
return rv | ||
} |
Oops, something went wrong.