Skip to content

Commit

Permalink
Merge pull request #43 from waybackarchiver/fix-cookies
Browse files Browse the repository at this point in the history
Fix `--load-cookies` not works
  • Loading branch information
RadhiFadlillah authored Nov 19, 2022
2 parents 3d6752a + ff26ebe commit 23c015a
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
12 changes: 10 additions & 2 deletions archiver.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@ var (

// Request is data of archival request.
type Request struct {
Input io.Reader
URL string
Input io.Reader
URL string

// Deprecated: Use `Archiver.WithCookies` instead.
Cookies []*http.Cookie

origin *nurl.URL // The original URL request was based from the input. If there are no redirects, it should be the same as `URL`.
Expand Down Expand Up @@ -147,6 +149,12 @@ func (arc *Archiver) Archive(ctx context.Context, req Request) ([]byte, string,
return s2b(result), contentType, nil
}

// WithCookies attach request cookies to `Archiver`.
func (arc *Archiver) WithCookies(cookies []*http.Cookie) *Archiver {
arc.cookies = cookies
return arc
}

// finalURI returns the final URL that has been redirected to another URL.
func (arc *Archiver) finalURI(u *nurl.URL) *nurl.URL {
req, err := http.NewRequest(http.MethodHead, u.String(), nil)
Expand Down
5 changes: 2 additions & 3 deletions cmd/obelisk/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,16 +192,15 @@ func cmdHandler(cmd *cobra.Command, args []string) error {
}

req := obelisk.Request{
URL: url.String(),
Cookies: reqCookies,
URL: url.String(),
}

// Start archival
if !disableLog || len(requests) > 1 {
logrus.Printf("archival started for %s\n", request.URL)
}

result, contentType, err := archiver.Archive(context.Background(), req)
result, contentType, err := archiver.WithCookies(reqCookies).Archive(context.Background(), req)
if err != nil {
return err
}
Expand Down
1 change: 1 addition & 0 deletions process-html.go
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,7 @@ func (arc *Archiver) convertNoScriptToDiv(doc *html.Node, markNewDiv bool) {
// convertLazyImageAttrs convert attributes data-src and data-srcset
// which often found in lazy-loaded images and pictures, into basic attribute
// src and srcset, so images that can be loaded without JS.
//
//nolint:gocyclo,goconst
func (arc *Archiver) convertLazyImageAttrs(doc *html.Node) {
imageNodes := dom.GetAllNodesWithTag(doc, "img", "picture", "figure")
Expand Down

0 comments on commit 23c015a

Please sign in to comment.