Skip to content

Request help using page.SetExtraHeaders to set 'Host' header to do vhosted screenshots. #985

Closed Answered by CyberStryk
CyberStryk asked this question in Q&A
Discussion options

You must be logged in to vote

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:

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-A…

Replies: 2 comments 5 replies

Comment options

You must be logged in to vote
5 replies
@CyberStryk
Comment options

@ysmood
Comment options

@CyberStryk
Comment options

@ysmood
Comment options

@CyberStryk
Comment options

Comment options

You must be logged in to vote
0 replies
Answer selected by CyberStryk
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants