Index: src/shared/Utils.h |
=================================================================== |
--- a/src/shared/Utils.h |
+++ b/src/shared/Utils.h |
@@ -50,4 +50,21 @@ |
return trimmed; |
} |
+template <class T> |
+T ExtractHTTPHeader(const T& allHeaders, const T& targetHeaderName, const T& delimiter) |
Felix Dahlke
2014/11/03 04:58:16
1. I think we generally capitalise it like this: E
Oleksandr
2014/11/03 11:37:37
2. Http headers can be seperated by '\0' as well.
sergei
2014/11/03 14:17:46
If we really want to have it in utils then tests a
Oleksandr
2014/11/04 12:02:42
Yes, I can see how the changes to make this more g
Felix Dahlke
2014/11/04 16:13:25
Fully agree, good points Sergei.
|
+{ |
+ auto targetHeaderBeginsAt = allHeaders.find(targetHeaderName); |
+ if (targetHeaderBeginsAt == T::npos) |
+ { |
+ return T(); |
+ } |
+ targetHeaderBeginsAt += targetHeaderName.length(); |
+ auto targetHeaderEndsAt = allHeaders.find(delimiter, targetHeaderBeginsAt); |
+ if (targetHeaderEndsAt == T::npos) |
+ { |
+ return T(); |
+ } |
+ return allHeaders.substr(targetHeaderBeginsAt, targetHeaderEndsAt - targetHeaderBeginsAt); |
+} |
+ |
#endif // UTILS_H |