Skip to content

Use string_view in CookieParser::before_handle parsing #1024

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 1 commit into
base: master
Choose a base branch
from

Conversation

Sightem
Copy link
Contributor

@Sightem Sightem commented Apr 17, 2025

This PR refactors CookieParser::before_handle to use std::string_view for parsing the Cookie request header, avoiding extra std::string allocations during slicing and trimming

Tested against the original code with around 20 inputs, confirming identical output maps and rejection behavior.
Closes #1023

@Sightem
Copy link
Contributor Author

Sightem commented Apr 17, 2025

I tested the implementation against the old one using these:

std::vector<std::string> test_cookies = {
   // Basic cases
   "key=value",
   "key1=value1; key2=value2",
   " key=value ",
   "key = value ; nextkey = anothervalue ",
   // Quoted values
   "key=\"value\"",
   "key=\"\"",
   " key = \" spaced value \" ",
   "key=\"value with ; inside\"",
   "key=\"value with = inside\"",
   "key=",
   "key=;next=val",
   "key= ; next=val",
   // Edge cases
   "",
   "key",
   "=", 
   "=value",
   " key = ",
   "key=value;"
   ";key=value",
   "key1=value1;;key2=value2",
   "key= value ",
   "key=\" value \"",
   "utf8key=你好世界; other=val",
   "special=!@#$%^&*()_+",
   "SID=abc; something=\"\"; key3=val3"
}; 

@Sightem Sightem force-pushed the refactor/cookie-parser-string-view branch 2 times, most recently from b7b229e to 7fb3152 Compare April 20, 2025 21:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Use std::string_view in CookieParser::before_handle
1 participant