-
Notifications
You must be signed in to change notification settings - Fork 840
update compress plugin to use more functionality from libswoc #12544
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
looking to make use of more functionality from swoc within the compress plugin i noticed that it has a file path utilities that we can make use of
…mpression_algorithms to use swoc::TextView
…erate with swoc::TextView for consistency
…ressible and HostConfiguration::is_url_allowed
Good updates. Looks like there's a couple wrinkles to iron out though: https://ci.trafficserver.apache.org/job/Github_Builds/job/autest/31205/console
|
return compressible_status_codes_.contains(status_code); | ||
} |
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.
nice :)
…edicates and reserve space for host configurations
…or parameter detection
b310613
to
2190c85
Compare
938f3d0
to
80ffce1
Compare
@bneradt all looking good now on ci :D |
{ | ||
using namespace std; | ||
|
||
void | ||
ltrim_if(string &s, int (*fp)(int)) | ||
inline auto | ||
make_char_predicate(int (*fp)(int)) | ||
{ | ||
for (size_t i = 0; i < s.size();) { | ||
if (fp(s[i])) { | ||
s.erase(i, 1); | ||
} else { | ||
break; | ||
} | ||
} | ||
return [fp](char c) -> bool { return fp(static_cast<unsigned char>(c)) != 0; }; | ||
} | ||
|
||
void | ||
rtrim_if(string &s, int (*fp)(int)) | ||
swoc::TextView | ||
extractFirstToken(swoc::TextView &view, int (*fp)(int)) | ||
{ | ||
for (ssize_t i = static_cast<ssize_t>(s.size()) - 1; i >= 0; i--) { | ||
if (fp(s[i])) { | ||
s.erase(i, 1); | ||
} else { | ||
break; | ||
} | ||
} | ||
} | ||
|
||
void | ||
trim_if(string &s, int (*fp)(int)) | ||
{ | ||
ltrim_if(s, fp); | ||
rtrim_if(s, fp); | ||
} | ||
|
||
string | ||
extractFirstToken(string &s, int (*fp)(int)) | ||
{ | ||
int startTok{-1}, endTok{-1}, idx{0}; | ||
|
||
for (;; ++idx) { | ||
if (idx == int(s.length())) { | ||
if (endTok < 0) { | ||
endTok = idx; | ||
} | ||
break; | ||
} else if (fp(s[idx])) { | ||
if ((startTok >= 0) and (endTok < 0)) { | ||
endTok = idx; | ||
} | ||
} else if (endTok > 0) { | ||
break; | ||
} else if (startTok < 0) { | ||
startTok = idx; | ||
} | ||
} | ||
auto predicate = make_char_predicate(fp); |
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 don't think you need make_char_predicate
. You can just pass fp
directly to your *_if
TextView functions.
I've been working on the compress plugin quite a lot recently and came to learn about libswoc from another pull-request i was doing, I thought it was a really good library and that this plugin might benefit from using more of it's utilities
most of these commits are likely able to be landed individually, if it would be better to open each one as a separate pull-request/patch i can do that☺️