parsed_request.cpp 816 B

1234567891011121314151617181920212223242526272829303132
  1. #include "parsed_request.h"
  2. #include <util/string/strip.h>
  3. #include <util/generic/yexception.h>
  4. #include <util/string/cast.h>
  5. static inline TStringBuf StripLeft(const TStringBuf& s) noexcept {
  6. const char* b = s.begin();
  7. const char* e = s.end();
  8. StripRangeBegin(b, e);
  9. return TStringBuf(b, e);
  10. }
  11. TParsedHttpRequest::TParsedHttpRequest(const TStringBuf& str) {
  12. TStringBuf tmp;
  13. if (!StripLeft(str).TrySplit(' ', Method, tmp)) {
  14. ythrow yexception() << "bad request(" << ToString(str).Quote() << ")";
  15. }
  16. if (!StripLeft(tmp).TrySplit(' ', Request, Proto)) {
  17. ythrow yexception() << "bad request(" << ToString(str).Quote() << ")";
  18. }
  19. Proto = StripLeft(Proto);
  20. }
  21. TParsedHttpLocation::TParsedHttpLocation(const TStringBuf& req) {
  22. req.Split('?', Path, Cgi);
  23. }