Request help using page.SetExtraHeaders to set 'Host' header to do vhosted screenshots. #985
-
Hi! I've been working on a fork of projectdiscovery's httpx to try and get screenshots working for vhosted hosts. I'm trying to accomplish this using the page.SetExtraHeaders function using the line below:
None of the requests my server are getting 'Host: test.com' header set properly. Any ideas what I'm doing wrong? Is there an easier way to do this? I've gotten vhosting to work with launcher.New() options, but I'd rather not create a new browser for each request. Here is the screenshot function:
|
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 5 replies
-
Have you tried this? Line 46 in 938f47b |
Beta Was this translation helpful? Give feedback.
-
To set the "Host" request header use the To set any other request headers use the Example: package main
import (
"github.com/go-rod/rod"
)
func main() {
page := rod.New().MustConnect().MustPage("")
router := page.HijackRequests()
router.MustAdd("*", func(ctx *rod.Hijack) {
// To set the host Header use Req().Host:
ctx.Request.Req().Host = "test.host"
// DOES NOT WORK for setting host
ctx.Request.Req().Header.Set("Host", "does.not.set.host")
// To set any other headers use the Req.Header.Set() function
ctx.Request.Req().Header.Set("User-Agent", "test-agent")
ctx.Request.Req().Header.Set("Accept-Language", "test-language")
ctx.Request.Req().Header.Set("Accept", "test/html")
ctx.Request.Req().Header.Set("Upgrade-Insecure-Requests", "test-insecure")
ctx.Request.Req().Header.Set("Accept-Encoding", "test-encoding")
// Load the response using the modified request
ctx.MustLoadResponse()
})
go router.Run()
page.MustNavigate("http://127.0.0.1/")
} Example output:
|
Beta Was this translation helpful? Give feedback.
Page.SetExtraHeaders
does not allow for modifying the host header.To set the "Host" request header use the
Request.Req().Host
variable.To set any other request headers use the
Request.Req().Header.Set()
function.Example: