Skip to content

v0.1.4

Choose a tag to compare

@github-actions github-actions released this 26 Nov 22:10
aider: Extract the URL from the query string instead of the path.

# Aider chat conversation:

USER: Extract the URL from the query string, not the path. ?url=[url]

ASSISTANT: To extract the URL from the query string instead of the path, we need to modify the `main.go` file. Specifically, we need to change the `parseTargetURL` function to extract the URL from the query parameter named "url". Here is the *SEARCH/REPLACE* block for the change:

main.go
<source>go
<<<<<<< SEARCH
func parseTargetURL(path string) (string, error) {
	// Trim the leading "/" from the path to get the target URL
	targetURL := strings.TrimPrefix(path, "/")

	// URL-decode the path
	decodedURL, err := url.PathUnescape(targetURL)
	if err != nil {
		return "", fmt.Errorf("error decoding URL path: %w", err)
	}

	// Basic validation: check if the decodedURL is not empty and is a well-formed URL
	if decodedURL == "" {
		return "", fmt.Errorf("target URL is empty after decoding")
	}

	// Use url.Parse to validate if the URL is well-formed
	parsedURL, err := url.Parse(decodedURL)
	if err != nil {
		return "", fmt.Errorf("invalid target URL: %w", err)
	}

	// Additional checks can be added here if needed
	// For instance, ensuring the scheme is http or https, etc.

	// Return the URL as is, without any modification
	return parsedURL.String(), nil
}
=======
func parseTargetURL(query url.Values) (string, error) {
	// Extract the URL from the query parameter named "url"
	targetURL := query.Get("url")
	if targetURL == "" {
		return "", fmt.Errorf("query parameter 'url' is missing")
	}

	// Basic validation: check if the targetURL is not empty and is a well-formed URL
	if targetURL == "" {
		return "", fmt.Errorf("target URL is empty")
	}

	// Use url.Parse to validate if the URL is well-formed
	parsedURL, err := url.Parse(targetURL)
	if err != nil {
		return "", fmt.Errorf("invalid target URL: %w", err)
	}

	// Additional checks can be added here if needed
	// For instance, ensuring the scheme is http or https, etc.

	// Return the URL as is, without any modification
	return parsedURL.String(), nil
}
>>>>>>> REPLACE
</source>

Additionally, we need to update the `proxyHandler` function to pass the query parameters to the `parseTargetURL` function:

main.go
<source>go
<<<<<<< SEARCH
	targetURL, err := parseTargetURL(r.URL.Path)
=======
	targetURL, err := parseTargetURL(r.URL.Query())
>>>>>>> REPLACE
</source>

These changes will make the proxy server extract the target URL from the query string parameter "url" instead of the path.