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
Share code between DefaultHttpHeaders, NettyH2HeadersToHttpHeaders, ReadOnlyHttpHeaders #537
Comments
I'll work on it. I think I can solve it by creating a class like |
@heowc great to know that you are interested in working on this. Sharing code between I would suggest trying code reuse between Good luck 😄 |
I was readed code about So, I thought about creating the following code from @Nullable
public static HttpCookiePair getCookie(Iterator<Map.Entry<CharSequence, CharSequence>> iterator,
Predicate<Map.Entry<CharSequence, CharSequence>> predicate,
final CharSequence name) {
return StreamSupport.stream(Spliterators.spliteratorUnknownSize(iterator, Spliterator.ORDERED), false)
.filter(predicate)
.map(entry -> parseCookiePair(entry.getValue(), name))
.findFirst().orElse(null);
} If apply the code, @Nullable
@Override
public HttpCookiePair getCookie(final CharSequence name) {
// ...
final Iterator<Map.Entry<CharSequence, CharSequence>> iterator = iterator();
return HeaderUtils.getCookie(iterator, entry -> hashCode(entry.getKey()) == nameHash && contentEqualsIgnoreCase(entry.getKey(), COOKIE), name);
} What do you think? Please give feedback if you have a better opinion. |
@heowc for header iteration/modification, we prefer utilizing the internal datastructure (associative array) over using the However, the approach to share code through Are you also looking at modifying other cookie related methods also? eg: |
Sorry, the answer is late. I changed the code almost similarly: # ReadOnlyHttpHeaders
int i = 0;
do {
final CharSequence currentName = keyValuePairs[i];
final CharSequence currentValue = keyValuePairs[i + 1];
if (nameHash == hashCode(currentName) && equals(currentName, COOKIE)) {
HttpCookiePair cookiePair = parseCookiePair(currentValue, name);
if (cookiePair != null) {
return cookiePair;
}
}
i += 2;
} while (i < end); # DefaultHttpHeaders
MultiMapEntry<CharSequence, CharSequence> e = bucketHead.entry;
assert e != null;
do {
final CharSequence currentName = e.getKey();
final CharSequence currentValue = e.getValue();
if (e.keyHash == nameHash && contentEqualsIgnoreCase(currentName, COOKIE)) {
HttpCookiePair cookiePair = parseCookiePair(currentValue, name);
if (cookiePair != null) {
return cookiePair;
}
}
e = e.bucketNext;
} while (e != null); |
Let me ping @Scottmitch about the intent of sharing code here, he might have better suggestions. |
The header implementations have commonalities between cookie parsing. Can we share code and consolidate?
The text was updated successfully, but these errors were encountered: