Skip to content
This repository has been archived by the owner on Mar 1, 2023. It is now read-only.

Add replacements for hostName and hostPort #35

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions ruleReplaceAction.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"strconv"
"strings"
"time"
"net"
)

var paramReplacementPattern = regexp.MustCompile("\\{[a-zA-Z0-9_\\-.]+}")
Expand Down Expand Up @@ -87,6 +88,12 @@ func (instance *ruleReplaceAction) contextRequestValueBy(name string) (string, b
return request.Method, true
case "host":
return request.Host, true
case "hostonly":
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi. Maybe you can change it to hostName and add another line for hostPort, too. That it might be aligned.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How to get the default port in error case? Is it enough to test the scheme and return 80 or 443?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes this makes sense.

host, _, err := net.SplitHostPort(request.Host)
if err != nil {
return request.Host, true
}
return host, true
case "proto":
return request.Proto, true
case "remoteAddress":
Expand Down