-
-
Notifications
You must be signed in to change notification settings - Fork 520
feat(endpoints): Add body to TCP, UDP, and TLS endpoints and templating #1134
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
base: master
Are you sure you want to change the base?
Conversation
README.md
Outdated
If `endpoints[].body` is set it is sent and the first 1024 bytes will be in `[BODY]`. You can use Go template | ||
syntax. The functions LocalAddr and RandomString with a length can be used. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you explain what the advantage of adding Go template syntax support add here?
Given how the number of bytes is restricted to 1024, I can't really think of much use for adding Go templating
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The response is restricted to 1024 bytes, not the body that is sent. I need it because I am sending a SIP OPTIONS message which requires the local IP address and several random strings. It seems useful for other protocols, but I can certainly remove that part of the code if it would make more sense.
client/client.go
Outdated
"LocalAddr": func() string { | ||
return localAddr.String() | ||
}, | ||
"RandomString": func(n int) string { | ||
const availableCharacterBytes = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789" | ||
b := make([]byte, n) | ||
rand.Seed(time.Now().UnixNano()) | ||
for i := range b { | ||
b[i] = availableCharacterBytes[rand.Intn(len(availableCharacterBytes))] | ||
} | ||
return string(b) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see, this is why you want to use Go templating.
Honestly, I'm a little perplexed, because we're using placeholders (e.g. [ENDPOINT_NAME]
and functions (e.g. len([BODY])
) everywhere else, so it'd be weird if we only used Go templating here.
How would you feel about dropping Go templating and instead adding a function for RandomString
(e.g. rand(6)
where 6
is the number of character) and a placeholder for [LOCAL_ADDRESS]
? fwiw, I don't mind if you add support for those two only for TCP/UDP/TLS endpoints and ignore the rest - though it'd be nice if it was added everywhere - just for the sake of consistency.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can look at changing the templating. Using the Go standard stuff was just easiest. And yes, its seems best to have it everywhere. Let me work on those changes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I updated the templating to be more consistent. I applied it to all endpoints that use Body. I used [RANDOM_STRING_6] because the functions (rand(6)) are only in conditions. This seemed easier to understand.
rest of the application and added additional substritutions.
Summary
#659
Checklist
README.md
, if applicable.