Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hijack情况下,301跳转处理问题 #578

Closed
LeoHuang2015 opened this issue Apr 13, 2022 · 2 comments
Closed

Hijack情况下,301跳转处理问题 #578

LeoHuang2015 opened this issue Apr 13, 2022 · 2 comments

Comments

@LeoHuang2015
Copy link

LeoHuang2015 commented Apr 13, 2022

Rod Version: v0.105.1
在hijack request情况下,处理完特殊情况,正常情况通过ctx.LoadResponse(http.DefaultClient, true) 时,301跳转的url会有问题:
代码如下:

		router := page.HijackRequests()
		addErr := router.Add("*", "", func(ctx *rod.Hijack) {
			WebxHandle(ctx)
		})
		if addErr != nil {
			fmt.Println("[agent]HijackRequests add err: ", addErr)
			return
		}
		go router.Run()


func WebxHandle(ctx *rod.Hijack) {
	RequestHandler(ctx)
	// ResponseHandle(ctx)
}

func RequestHandler(ctx *rod.Hijack) {
	//  drop static request
	reqUrl := ctx.Request.URL()
	err := ctx.LoadResponse(http.DefaultClient, true)
	if err != nil {
		fmt.Println("[LoadResponse]Error.", reqUrl, err)
		ctx.Response.Fail(proto.NetworkErrorReasonAborted)
	}
}

如,请求:http://demo.aisec.cn/demo/aisec ,默认情况下会301跳转到 http://demo.aisec.cn/demo/aisec/ 。但是使用ctx.LoadResponse 会导致一种情况,response页面已经是新页面了,但是 url还是老的: http://demo.aisec.cn/demo/aisec , 里面的href 信息在浏览器自动拼接就会路径错误。 比如http://demo.aisec.cn/demo/js_link.php?id=2&msg=abc 正常应该是:http://demo.aisec.cn/demo/aisec/js_link.php?id=2&msg=abc

看了下代码, ctx.ContinueRequest(&proto.FetchContinueRequest{}) 似乎能解决这个问题,但是ctx.LoadResponse(http.DefaultClient, true) 的中间过程,是不是在hijack中体现出来?

@rod-robot
Copy link

Please add a valid **Rod Version:** v0.0.0 to your issue. Current version is v0.105.1
generated by check-issue

@ysmood
Copy link
Collaborator

ysmood commented Apr 13, 2022

#322

@ysmood ysmood closed this as completed Apr 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants