#include "webcc/request.h" namespace webcc { bool Request::IsForm() const { return std::dynamic_pointer_cast(body_) != nullptr; } const std::vector& Request::form_parts() const { auto form_body = std::dynamic_pointer_cast(body_); if (!form_body) { throw Error{ Error::kDataError, "Not a form body" }; } return form_body->parts(); } void Request::Prepare() { if (!start_line_.empty()) { return; } if (url_.host().empty()) { throw Error{ Error::kSyntaxError, "Host is missing" }; } std::string target = url_.path(); if (!url_.query().empty()) { target += "?"; target += url_.query(); } start_line_ = method_ + " " + target + " HTTP/1.1"; if (url_.port().empty()) { SetHeader(headers::kHost, url_.host()); } else { SetHeader(headers::kHost, url_.host() + ":" + url_.port()); } } } // namespace webcc