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: |
Answered by
CyberStryk
Dec 3, 2023
Replies: 2 comments 5 replies
|
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: |
0 replies
Answer selected by
CyberStryk
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Page.SetExtraHeadersdoes not allow for modifying the host header.To set the "Host" request header use the
Request.Req().Hostvariable.To set any other request headers use the
Request.Req().Header.Set()function.Example: