diff --git a/include/http_header.h b/include/http_header.h index e8c6ad316..f2ab1eb71 100644 --- a/include/http_header.h +++ b/include/http_header.h @@ -66,6 +66,12 @@ enum class Encoding { Unknown }; +// Content Dispositions +enum class Disposition { + Inline, + Attachment +}; + const char* encodingString(Encoding encoding); class Header { @@ -249,6 +255,33 @@ class TransferEncoding : public EncodingHeader { { } }; +class ContentDisposition : public Header { +public: + NAME("Content-Disposition"); + + ContentDisposition() + : disposition_(Disposition::Inline) + , filename_("") + { } + + ContentDisposition(Disposition disposition) + : disposition_(disposition) + , filename_("") + { } + + ContentDisposition(Disposition disposition, const std::string & filename) + : disposition_(disposition) + , filename_(filename) + { } + + void parseRaw(const char* str, size_t len); + void write(std::ostream& os) const; + +private: + Disposition disposition_; + std::string filename_; +}; + class ContentLength : public Header { public: NAME("Content-Length"); @@ -353,6 +386,25 @@ class Host : public Header { Net::Port port_; }; +class LastModified : public Header { +public: + NAME("Last-Modified") + + LastModified() { } + + explicit LastModified(const FullDate& date) : + fullDate_(date) + { } + + void parseRaw(const char* str, size_t len); + void write(std::ostream& os) const; + + FullDate fullDate() const { return fullDate_; } + +private: + FullDate fullDate_; +}; + class Location : public Header { public: NAME("Location") diff --git a/src/common/http_header.cc b/src/common/http_header.cc index dd7dc9305..945c6c4a8 100644 --- a/src/common/http_header.cc +++ b/src/common/http_header.cc @@ -286,6 +286,26 @@ Connection::write(std::ostream& os) const { } } + +void +ContentDisposition::parseRaw(const char* str, size_t len) { +} + +void +ContentDisposition::write(std::ostream& os) const { + switch(disposition_) { + case Disposition::Inline: + os << "inline"; + break; + case Disposition::Attachment: + os << "attachment"; + if(!filename_.empty()) { + os << "; filename=" << filename_; + } + break; + } +} + void ContentLength::parse(const std::string& data) { try { @@ -311,6 +331,7 @@ Date::parseRaw(const char* str, size_t len) { void Date::write(std::ostream& os) const { + fullDate_.write(os, Net::Http::FullDate::Type::RFC1123); } void @@ -359,6 +380,17 @@ Host::write(std::ostream& os) const { } } +void +LastModified::parseRaw(const char* str, size_t len) { + fullDate_ = FullDate::fromRaw(str, len); +} + +void +LastModified::write(std::ostream& os) const { + fullDate_.write(os, Net::Http::FullDate::Type::RFC1123); +} + + Location::Location(const std::string& location) : location_(location) { } diff --git a/src/common/http_headers.cc b/src/common/http_headers.cc index 76e560a46..2018e41cf 100644 --- a/src/common/http_headers.cc +++ b/src/common/http_headers.cc @@ -24,6 +24,7 @@ RegisterHeader(Accept); RegisterHeader(Allow); RegisterHeader(CacheControl); RegisterHeader(Connection); +RegisterHeader(ContentDisposition); RegisterHeader(ContentEncoding); RegisterHeader(TransferEncoding); RegisterHeader(ContentLength); @@ -31,6 +32,7 @@ RegisterHeader(ContentType); RegisterHeader(Date); RegisterHeader(Expect); RegisterHeader(Host); +RegisterHeader(LastModified); RegisterHeader(Location); RegisterHeader(Server); RegisterHeader(UserAgent);