The Crystal Programming Language Forum

Using Regex to parse HTTP cookies

I was looking through some of the PRs coming in and noticed HTTP cookies are parsed using regex. This seems like it would be more resource intensive then necessary for this task.

Would it be worth using an implementation HTTP cookie parsing uses more native to Crystal to reduce memory and cpu usage?

This would make the code more complex and I am interested if there are any opinions on using regex to parse cookies. Are there any other concerns in using regex to parse cookies?

Yes, a custom parser is definitly better. I alread have an implementation laying around, it was just pushed to the back for more urgent tasks. The regexes work, so there’s no pressure.

I was also looking into extending the cookie test suite to make sure the parser works correctly in all kinds of edge cases. The current specs are a bit thin in my opinion.
There should be some kind of generic test suite for this. I think I translated some tests from Golang, but they were not that many either. Most I could find were tests for browser behaviour, which is a bit different (it does more than just serializing and deserializing).