mirror of
https://github.com/stashapp/stash.git
synced 2025-12-15 04:44:28 +01:00
Resolve hostname for chromium RDP requests (#2174)
This commit is contained in:
parent
1714efc92f
commit
be5dc7e545
2 changed files with 31 additions and 2 deletions
|
|
@ -5,6 +5,7 @@ import (
|
|||
"context"
|
||||
"fmt"
|
||||
"io"
|
||||
"net"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"os"
|
||||
|
|
@ -87,7 +88,7 @@ func loadURL(ctx context.Context, loadURL string, client *http.Client, scraperCo
|
|||
// func urlFromCDP uses chrome cdp and DOM to load and process the url
|
||||
// if remote is set as true in the scraperConfig it will try to use localhost:9222
|
||||
// else it will look for google-chrome in path
|
||||
func urlFromCDP(ctx context.Context, url string, driverOptions scraperDriverOptions, globalConfig GlobalConfig) (io.Reader, error) {
|
||||
func urlFromCDP(ctx context.Context, urlCDP string, driverOptions scraperDriverOptions, globalConfig GlobalConfig) (io.Reader, error) {
|
||||
|
||||
if !driverOptions.UseCDP {
|
||||
return nil, fmt.Errorf("url shouldn't be fetched through CDP")
|
||||
|
|
@ -107,6 +108,33 @@ func urlFromCDP(ctx context.Context, url string, driverOptions scraperDriverOpti
|
|||
if isCDPPathHTTP(globalConfig) || isCDPPathWS(globalConfig) {
|
||||
remote := cdpPath
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
// #1023
|
||||
// when chromium is listening over RDP it only accepts requests
|
||||
// with host headers that are either IPs or `localhost`
|
||||
cdpURL, err := url.Parse(remote)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to parse CDP Path: %v", err)
|
||||
}
|
||||
hostname := cdpURL.Hostname()
|
||||
if hostname != "localhost" {
|
||||
if net.ParseIP(hostname) == nil { // not an IP
|
||||
addr, err := net.LookupIP(hostname)
|
||||
if err != nil || len(addr) == 0 { // can not resolve to IP
|
||||
return nil, fmt.Errorf("CDP: hostname <%s> can not be resolved", hostname)
|
||||
}
|
||||
if len(addr[0]) == 0 { // nil IP
|
||||
return nil, fmt.Errorf("CDP: hostname <%s> resolved to nil", hostname)
|
||||
}
|
||||
// addr is a valid IP
|
||||
// replace the host part of the cdpURL with the IP
|
||||
cdpURL.Host = strings.Replace(cdpURL.Host, hostname, addr[0].String(), 1)
|
||||
// use that for remote
|
||||
remote = cdpURL.String()
|
||||
}
|
||||
}
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
// if CDPPath is http(s) then we need to get the websocket URL
|
||||
if isCDPPathHTTP(globalConfig) {
|
||||
var err error
|
||||
|
|
@ -150,7 +178,7 @@ func urlFromCDP(ctx context.Context, url string, driverOptions scraperDriverOpti
|
|||
setCDPCookies(driverOptions),
|
||||
printCDPCookies(driverOptions, "Cookies found"),
|
||||
network.SetExtraHTTPHeaders(network.Headers(headers)),
|
||||
chromedp.Navigate(url),
|
||||
chromedp.Navigate(urlCDP),
|
||||
chromedp.Sleep(sleepDuration),
|
||||
setCDPClicks(driverOptions),
|
||||
chromedp.OuterHTML("html", &res, chromedp.ByQuery),
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@
|
|||
* Show counts on list tabs in Performer, Studio and Tag pages. ([#2169](https://github.com/stashapp/stash/pull/2169))
|
||||
|
||||
### 🐛 Bug fixes
|
||||
* Resolve CDP hostname if necessary. ([#2174](https://github.com/stashapp/stash/pull/2174))
|
||||
* Generate sprites for short video files. ([#2167](https://github.com/stashapp/stash/pull/2167))
|
||||
* Fix stash-box scraping including underscores in ethnicity. ([#2191](https://github.com/stashapp/stash/pull/2191))
|
||||
* Fix stash-box batch performer task not setting birthdate. ([#2189](https://github.com/stashapp/stash/pull/2189))
|
||||
|
|
|
|||
Loading…
Reference in a new issue