Skip to content
This repository was archived by the owner on Feb 29, 2024. It is now read-only.
This repository was archived by the owner on Feb 29, 2024. It is now read-only.

problems about WebTextHandler #2

@CoolSpring8

Description

@CoolSpring8

Currently we have this in internal/proxy/proxy.go:

// WebTextHandler fixes links in page and "src" issues in javascript files.
// This solution, however, may prevent content streaming. Fix it?
func WebTextHandler() goproxy.RespHandler {
	return goproxy_html.HandleString(
		func(s string, ctx *goproxy.ProxyCtx) string {
			c := RVPNURLMatcher.ReplaceAllString(s, "$1://")
			rawURLWithPort := ctx.UserData.(reqData).rawURLWithPort
			rawURLWithoutPort := ctx.UserData.(reqData).rawURLWithoutPort
			c = strings.ReplaceAll(c, rawURLWithPort[:strings.LastIndex(rawURLWithPort, "/")+1], "") // possible out of bounds?
			c = strings.ReplaceAll(c, rawURLWithoutPort[:strings.LastIndex(rawURLWithoutPort, "/")+1], "")
			return c
		})
}

As the comments indicates, there are several problems.

  1. Issue of "src" in javascript files is not completely resolved. Corruption of scripts still exists on some sites.
  2. Out of bounds in trying to get the string before (including) last "/".
  3. Streaming of response. Apparently for now the result is first "ReadAll"-ed, processed and sent to the browser.

Solutions and plans:

  • 1: This requires a close inspecting and some experiments on some sites.
  • 2: A better way to do the extracting. Note since this is also related to "src" issue as mentioned above, if we can find other ways to solve that, there is no need to do this substitution anymore.
  • 3: This is more of a performance concern. Let's have a detailed explanation in the next reply.

And one more small thing: CSS files can probably be excluded from being applied with this handler.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requesthelp wantedExtra attention is needed

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions