Unverified Commit 7cb671e0 authored by Dennis Jenkins's avatar Dennis Jenkins Committed by GitHub

Merge pull request #551 from kiplingw/kip-raw-headers

All raw headers are now preserved
parents b68082f8 5bb31160
......@@ -16,9 +16,24 @@ Pistache was originally created by Mathieu Stefani, but he is no longer actively
For those that prefer IRC over Slack, the rag-tag crew of maintainers idle in `#pistache` on Freenode. Please come and join us!
# Precompiled packages
# Precompiled Packages
## Ubuntu PPA (Stable)
## Debian and Ubuntu
We have submitted both a [Request for Packaging](https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=929593) and a [Request for Sponsorship](https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=927839) downstream to Debian. Once Pistache has an official Debian package maintainer intimately familiar with the [Debian Policy Manual](https://www.debian.org/doc/debian-policy/), we can expect to eventually see Pistache available in Debian and all Debian based distributions (e.g. Ubuntu and many others).
But until then currently Pistache has partially compliant upstream Debianization. Our long term goal is to have our source package properly Debianized downstream by a Debian Policy Manual SME. In the mean time consider using our PPAs to avoid having to build from source.
### Supported Architectures
Currently Pistache is built and tested on a number of [architectures](https://wiki.debian.org/SupportedArchitectures). Some of these are suitable for desktop or server use and others for embedded environments. As of this writing we do not currently have any MIPS related packages that have been either built or tested.
- amd64
- arm64
- armhf (build fails at this moment)
- i386
- ppc64el
- s390x
### Ubuntu PPA (Stable)
If you would like to use [stable](https://launchpad.net/%7Ekip/+archive/ubuntu/pistache) packages, run the following:
```console
......@@ -27,7 +42,7 @@ $ sudo apt update
$ sudo apt install libpistache-dev
```
## Ubuntu PPA (Unstable)
### Ubuntu PPA (Unstable)
To use [unstable](https://launchpad.net/%7Ekip/+archive/ubuntu/pistache-unstable) packages, run the following:
```console
......@@ -53,7 +68,7 @@ To use with the GNU Autotools, as an example, include the following snippet in y
```
# To Build:
# Building from source
To download the latest available release, clone the repository over github.
......
pistache (0.0.001-git20190611-kip1~disco) disco; urgency=medium
* Built from latest git head.
-- Kip Warner <kip@thevertigo.com> Tue, 11 Jun 2019 18:35:18 -0700
pistache (0.0.001-git20190526-kip1~disco) disco; urgency=medium
* Built from latest git head.
......
......@@ -297,15 +297,19 @@ namespace Private {
else if (name == "Set-Cookie") {
message->cookies_.add(Cookie::fromRaw(cursor.offset(start), cursor.diff(start)));
}
// If the header is registered with the Registry, add its strongly
// typed form to the headers list...
else if (Header::Registry::instance().isRegistered(name)) {
std::shared_ptr<Header::Header> header = Header::Registry::instance().makeHeader(name);
header->parseRaw(cursor.offset(start), cursor.diff(start));
message->headers_.add(header);
}
else {
std::string value(cursor.offset(start), cursor.diff(start));
message->headers_.addRaw(Header::Raw(std::move(name), std::move(value)));
}
// But also preserve a raw header version too, regardless of whether
// its type was known to the Registry...
std::string value(cursor.offset(start), cursor.diff(start));
message->headers_.addRaw(Header::Raw(std::move(name), std::move(value)));
// CRLF
if (!cursor.advance(2)) return State::Again;
......
#include <pistache/http_headers.h>
#include <pistache/http.h>
#include <pistache/date.h>
#include "gtest/gtest.h"
......@@ -647,3 +647,45 @@ TEST(headers_test, could_not_find_header)
ASSERT_TRUE("Unknown header" == what);
}
// Verify registered headers appear in both the client request's strongly typed
// and raw lists...
TEST(headers_test, registered_header_in_raw_list)
{
// Make sure TestHeader is registered because Googletest does not guarantee
// add_new_header_test will be run before this test...
if(!Pistache::Http::Header::Registry::instance().isRegistered(TestHeader::Name))
Pistache::Http::Header::Registry::instance().registerHeader<TestHeader>();
// Verify test header is registered...
ASSERT_TRUE(Pistache::Http::Header::Registry::instance().isRegistered(TestHeader::Name));
// Prepare a client request header string that should use our registered
// TestHeader...
std::string line = std::string(TestHeader::Name) + ": some data\r\n";
// Prepare to load the client test header string...
Pistache::RawStreamBuf<> buf(&line[0], line.size());
Pistache::StreamCursor cursor(&buf);
// Simulate server deserializing the client's header request...
Pistache::Http::Request request;
Pistache::Http::Private::HeadersStep step(&request);
step.apply(cursor);
// Retrieve all of the headers the client submitted in their request...
const auto &headersCollection = request.headers();
// Verify our TestHeader is in the strongly typed list...
ASSERT_TRUE(headersCollection.has<TestHeader>());
// Obtain the raw header list...
const auto &rawHeadersList = headersCollection.rawList();
// Verify the TestHeader is in the raw list as expected...
const auto foundRawHeader = rawHeadersList.find(TestHeader::Name);
ASSERT_TRUE(foundRawHeader != rawHeadersList.end());
ASSERT_TRUE(foundRawHeader->second.name() == TestHeader::Name);
ASSERT_TRUE(foundRawHeader->second.value() == "some data");
}
VERSION_MAJOR 0
VERSION_MINOR 0
VERSION_PATCH 001
VERSION_GIT_DATE 20190526
VERSION_GIT_DATE 20190611
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment