Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions include/http_header.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,12 @@ enum class Encoding {
Unknown
};

// Content Dispositions
enum class Disposition {
Inline,
Attachment
};

const char* encodingString(Encoding encoding);

class Header {
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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")
Expand Down
32 changes: 32 additions & 0 deletions src/common/http_header.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
Expand Down Expand Up @@ -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)
{ }
Expand Down
2 changes: 2 additions & 0 deletions src/common/http_headers.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,15 @@ RegisterHeader(Accept);
RegisterHeader(Allow);
RegisterHeader(CacheControl);
RegisterHeader(Connection);
RegisterHeader(ContentDisposition);
RegisterHeader(ContentEncoding);
RegisterHeader(TransferEncoding);
RegisterHeader(ContentLength);
RegisterHeader(ContentType);
RegisterHeader(Date);
RegisterHeader(Expect);
RegisterHeader(Host);
RegisterHeader(LastModified);
RegisterHeader(Location);
RegisterHeader(Server);
RegisterHeader(UserAgent);
Expand Down