| 1 |
|
| MODE: INLINE
|
| 2 |
|
| #include <xs/uri.h>
|
| 3 |
|
|
|
| 4 |
|
| namespace {
|
| 5 |
|
| struct XSRequest : Request, Backref {
|
| 6 |
|
| using Request::Request;
|
| 7 |
|
|
|
| 8 |
|
| ResponseSP new_response () const override { return make_backref<Response>(); }
|
| 9 |
|
|
|
| 10 |
|
| ~XSRequest () { Backref::dtor(); }
|
| 11 |
|
| };
|
| 12 |
|
| }
|
| 13 |
|
|
|
| 14 |
|
| MODULE = Protocol::HTTP PACKAGE = Protocol::HTTP::Request
|
| 15 |
|
| PROTOTYPES: DISABLE
|
| 16 |
|
|
|
| 17 |
|
| BOOT {
|
| 18 |
|
| using M = Request::Method;
|
| 19 |
|
| using E = Request::EncType;
|
| 20 |
0 |
▶ | Stash s(__PACKAGE__);
|
Branch: 1 branch
| Branch | True | False | Total |
| Stash s(__PACKAGE__);
|
0 |
0 |
0 |
|
| 21 |
0 |
▶ | s.inherit("Protocol::HTTP::Message");
|
Branch: 1 branch
| Branch | True | False | Total |
| s.inherit("Protocol::HTTP::Message");
|
0 |
0 |
0 |
|
| 22 |
0 |
▶ | xs::exp::create_constants(s, {
|
Branch: 4 branches
| Branch | True | False | Total |
| xs::exp::create_constants(s, {
|
0 |
0 |
0 |
| xs::exp::create_constants(s, {
|
0 |
0 |
0 |
| xs::exp::create_constants(s, {
|
0 |
0 |
0 |
| xs::exp::create_constants(s, {
|
0 |
0 |
0 |
|
| 23 |
|
| {"METHOD_UNSPECIFIED", int(M::Unspecified)},
|
| 24 |
|
| {"METHOD_OPTIONS", int(M::Options) },
|
| 25 |
|
| {"METHOD_GET", int(M::Get) },
|
| 26 |
|
| {"METHOD_HEAD", int(M::Head) },
|
| 27 |
|
| {"METHOD_POST", int(M::Post) },
|
| 28 |
|
| {"METHOD_PUT", int(M::Put) },
|
| 29 |
|
| {"METHOD_DELETE", int(M::Delete) },
|
| 30 |
|
| {"METHOD_TRACE", int(M::Trace) },
|
| 31 |
|
| {"METHOD_CONNECT", int(M::Connect) },
|
| 32 |
|
|
|
| 33 |
|
| {"ENCODING_MULTIPART", int(E::Multipart)},
|
| 34 |
|
| {"ENCODING_URL", int(E::UrlEncoded)},
|
| 35 |
|
| });
|
| 36 |
0 |
▶ | xs::exp::autoexport(s);
|
Branch: 2 branches
| Branch | True | False | Total |
| xs::exp::autoexport(s);
|
0 |
0 |
0 |
| xs::exp::autoexport(s);
|
0 |
0 |
0 |
|
| 37 |
0 |
| }
|
| 38 |
|
|
|
| 39 |
|
| RequestSP Request::new (Hash params = Hash()) {
|
| 40 |
0 |
| RETVAL = new XSRequest();
|
| 41 |
0 |
▶ | if (params) {
|
Branch: 1 branch
| Branch | True | False | Total |
| if (params) {
|
0 |
0 |
0 |
|
| 42 |
0 |
▶ | fill(RETVAL, params);
|
Branch: 3 branches
| Branch | True | False | Total |
| fill(RETVAL, params);
|
0 |
0 |
0 |
| fill(RETVAL, params);
|
0 |
0 |
0 |
| fill(RETVAL, params);
|
0 |
0 |
0 |
|
| 43 |
0 |
▶ | fill_form(RETVAL, params["form"]);
|
Branch: 1 branch
| Branch | True | False | Total |
| fill_form(RETVAL, params["form"]);
|
0 |
0 |
0 |
|
| 44 |
0 |
▶ | }
|
Branch: 1 branch
| Branch | True | False | Total |
| }
|
0 |
0 |
0 |
|
| 45 |
0 |
▶ | }
|
Branch: 2 branches
| Branch | True | False | Total |
| }
|
0 |
0 |
0 |
| }
|
0 |
0 |
0 |
|
| 46 |
|
|
|
| 47 |
|
| int Request::method_raw (SV* newval = NULL) {
|
| 48 |
0 |
▶ | if (newval) {
|
Branch: 1 branch
| Branch | True | False | Total |
| if (newval) {
|
0 |
0 |
0 |
|
| 49 |
0 |
▶ | set_method(THIS, newval);
|
Branch: 1 branch
| Branch | True | False | Total |
| set_method(THIS, newval);
|
0 |
0 |
0 |
|
| 50 |
0 |
| XSRETURN_UNDEF;
|
| 51 |
|
| }
|
| 52 |
0 |
| RETVAL = int(THIS->method_raw());
|
| 53 |
|
| }
|
| 54 |
|
|
|
| 55 |
|
| int Request::method(SV* newval = NULL) {
|
| 56 |
0 |
▶ | if (newval) {
|
Branch: 1 branch
| Branch | True | False | Total |
| if (newval) {
|
0 |
0 |
0 |
|
| 57 |
0 |
▶ | set_method(THIS, newval);
|
Branch: 1 branch
| Branch | True | False | Total |
| set_method(THIS, newval);
|
0 |
0 |
0 |
|
| 58 |
0 |
| XSRETURN_UNDEF;
|
| 59 |
|
| }
|
| 60 |
0 |
| RETVAL = int(THIS->method());
|
| 61 |
|
| }
|
| 62 |
|
|
|
| 63 |
|
| string method_str (Sv item) {
|
| 64 |
0 |
| int value = -1;
|
| 65 |
0 |
▶ | if (item.is_simple()) {
|
Branch: 1 branch
| Branch | True | False | Total |
| if (item.is_simple()) {
|
0 |
0 |
0 |
|
| 66 |
0 |
▶ | value = Simple(item).as_number<int>();
|
Branch: 2 branches
| Branch | True | False | Total |
| value = Simple(item).as_number<int>();
|
0 |
0 |
0 |
| value = Simple(item).as_number<int>();
|
0 |
0 |
0 |
|
| 67 |
|
| } else {
|
| 68 |
0 |
▶ | auto req = xs::in<Request*>(item);
|
Branch: 1 branch
| Branch | True | False | Total |
| auto req = xs::in<Request*>(item);
|
0 |
0 |
0 |
|
| 69 |
0 |
| auto method = req->method();
|
| 70 |
0 |
| value = static_cast<int>(method);
|
| 71 |
|
| }
|
| 72 |
0 |
▶ | RETVAL = Request::method_str(static_cast<Request::Method>(value));
|
Branch: 1 branch
| Branch | True | False | Total |
| RETVAL = Request::method_str(static_cast<Request::Method>(value));
|
0 |
0 |
0 |
|
| 73 |
|
| }
|
| 74 |
|
|
|
| 75 |
|
| URISP Request::uri (URISP newval = NULL) {
|
| 76 |
0 |
| if (newval) {
|
| 77 |
0 |
▶ | THIS->uri = newval;
|
Branch: 1 branch
| Branch | True | False | Total |
| THIS->uri = newval;
|
0 |
0 |
0 |
|
| 78 |
0 |
▶ | XSRETURN_UNDEF;
|
Branch: 1 branch
| Branch | True | False | Total |
| XSRETURN_UNDEF;
|
0 |
0 |
0 |
|
| 79 |
0 |
| }
|
| 80 |
|
| RETVAL = THIS->uri;
|
| 81 |
0 |
▶ | }
|
Branch: 1 branch
| Branch | True | False | Total |
| }
|
0 |
0 |
0 |
|
| 82 |
|
|
|
| 83 |
|
| Hash Request::cookies (Hash new_cookies = Hash()) {
|
| 84 |
0 |
▶ | if (new_cookies) {
|
Branch: 1 branch
| Branch | True | False | Total |
| if (new_cookies) {
|
0 |
0 |
0 |
|
| 85 |
0 |
▶ | set_request_cookies(THIS, new_cookies);
|
Branch: 1 branch
| Branch | True | False | Total |
| set_request_cookies(THIS, new_cookies);
|
0 |
0 |
0 |
|
| 86 |
0 |
| XSRETURN_UNDEF;
|
| 87 |
|
| }
|
| 88 |
|
|
|
| 89 |
0 |
▶ | RETVAL = Hash::create(THIS->cookies.size());
|
Branch: 1 branch
| Branch | True | False | Total |
| RETVAL = Hash::create(THIS->cookies.size());
|
0 |
0 |
0 |
|
| 90 |
0 |
▶ | for (const auto& elem : THIS->cookies.fields) RETVAL.store(elem.name, xs::out(elem.value));
|
Branch: 3 branches
| Branch | True | False | Total |
| for (const auto& elem : THIS->cookies.fields) RETVAL.store(elem.name, xs::out(elem.value));
|
0 |
0 |
0 |
| for (const auto& elem : THIS->cookies.fields) RETVAL.store(elem.name, xs::out(elem.value));
|
0 |
0 |
0 |
| for (const auto& elem : THIS->cookies.fields) RETVAL.store(elem.name, xs::out(elem.value));
|
0 |
0 |
0 |
|
| 91 |
|
| }
|
| 92 |
|
|
|
| 93 |
|
| string Request::cookie (string_view name, SV* val = nullptr) {
|
| 94 |
0 |
▶ | if (val) {
|
Branch: 1 branch
| Branch | True | False | Total |
| if (val) {
|
0 |
0 |
0 |
|
| 95 |
0 |
▶ | if (!SvOK(val)) THIS->cookies.remove(name);
|
Branch: 2 branches
| Branch | True | False | Total |
| if (!SvOK(val)) THIS->cookies.remove(name);
|
0 |
0 |
0 |
| if (!SvOK(val)) THIS->cookies.remove(name);
|
0 |
0 |
0 |
|
| 96 |
0 |
▶ | else THIS->cookies.set(string(name), xs::in<string>(val));
|
Branch: 3 branches
| Branch | True | False | Total |
| else THIS->cookies.set(string(name), xs::in<string>(val));
|
0 |
0 |
0 |
| else THIS->cookies.set(string(name), xs::in<string>(val));
|
0 |
0 |
0 |
| else THIS->cookies.set(string(name), xs::in<string>(val));
|
0 |
0 |
0 |
|
| 97 |
0 |
| XSRETURN_UNDEF;
|
| 98 |
|
| }
|
| 99 |
|
|
|
| 100 |
0 |
▶ | auto it = THIS->cookies.find(name);
|
Branch: 1 branch
| Branch | True | False | Total |
| auto it = THIS->cookies.find(name);
|
0 |
0 |
0 |
|
| 101 |
0 |
▶ | if (it == THIS->cookies.end()) XSRETURN_UNDEF;
|
Branch: 1 branch
| Branch | True | False | Total |
| if (it == THIS->cookies.end()) XSRETURN_UNDEF;
|
0 |
0 |
0 |
|
| 102 |
0 |
▶ | RETVAL = it->value;
|
Branch: 1 branch
| Branch | True | False | Total |
| RETVAL = it->value;
|
0 |
0 |
0 |
|
| 103 |
|
| }
|
| 104 |
|
|
|
| 105 |
|
| void Request::allow_compression (SV*, ...) {
|
| 106 |
0 |
▶ | for (int i = 1; i < items; ++i) {
|
Branch: 1 branch
| Branch | True | False | Total |
| for (int i = 1; i < items; ++i) {
|
0 |
0 |
0 |
|
| 107 |
0 |
| uint8_t val = SvIV(ST(i));
|
| 108 |
0 |
▶ | if (is_valid_compression(val)) THIS->allow_compression((Compression::Type)val);
|
Branch: 1 branch
| Branch | True | False | Total |
| if (is_valid_compression(val)) THIS->allow_compression((Compression::Type)val);
|
0 |
0 |
0 |
|
| 109 |
|
| }
|
| 110 |
|
| }
|
| 111 |
|
|
|
| 112 |
0 |
▶ | int Request::allowed_compression (bool inverse = false)
|
Branch: 1 branch
| Branch | True | False | Total |
| int Request::allowed_compression (bool inverse = false)
|
0 |
0 |
0 |
|
| 113 |
|
|
|
| 114 |
0 |
▶ | string Request::to_string ()
|
Branch: 2 branches
| Branch | True | False | Total |
| string Request::to_string ()
|
0 |
0 |
0 |
| string Request::to_string ()
|
0 |
0 |
0 |
|