Skip to content

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

jasonshugart
Copy link

Summary

#659

Checklist

  • Tested and/or added tests to validate that the changes work as intended, if applicable.
  • Updated documentation in README.md, if applicable.

@github-actions github-actions bot added the feature New feature or request label Jun 11, 2025
README.md Outdated
Comment on lines 2030 to 2031
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.
Copy link
Owner

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

Copy link
Author

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
Comment on lines 83 to 93
"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)
Copy link
Owner

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.

Copy link
Author

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.

Copy link
Author

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.
@jasonshugart jasonshugart requested a review from TwiN June 12, 2025 14:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants