8000 Fix content-type for JS APIs by graetzer · Pull Request #10225 · arangodb/arangodb · GitHub
[go: up one dir, main page]

Skip to content

Fix content-type for JS APIs #10225

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 14, 2019
Merged
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
20 changes: 11 additions & 9 deletions 3rdParty/fuerte/src/HttpConnection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -305,18 +305,20 @@ std::string HttpConnection<ST>::buildRequestBody(Request const& req) {
header.append("Connection: Close\r\n");
}

header.append("Content-Type: ")
.append(to_string(req.contentType()))
.append("\r\n")
.append("Accept: ")
.append(to_string(req.acceptType()))
.append("\r\n");
if (req.contentType() != ContentType::Custom) {
header.append("Content-Type: ")
.append(to_string(req.contentType()))
.append("\r\n");
}
if (req.acceptType() != ContentType::Custom) {
header.append("Accept: ")
.append(to_string(req.acceptType()))
.append("\r\n");
}

bool haveAuth = false;
for (auto const& pair : req.header.meta()) {
if (boost::iequals(fu_content_length_key, pair.first) ||
boost::iequals(fu_content_type_key, pair.first) ||
boost::iequals(fu_accept_key, pair.first)) {
if (boost::iequals(fu_content_length_key, pair.first)) {
continue; // skip content-length header
}

Expand Down
13 changes: 9 additions & 4 deletions 3rdParty/fuerte/src/message.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,17 @@ namespace arangodb { namespace fuerte { inline namespace v1 {

void MessageHeader::addMeta(std::string key, std::string value) {
if (boost::iequals(key, fu_accept_key)) {
this->_acceptType = to_ContentType(value);
_acceptType = to_ContentType(value);
if (_acceptType != ContentType::Custom) {
return;
}
} else if (boost::iequals(key, fu_content_type_key)) {
this->_contentType = to_ContentType(value);
} else {
this->_meta.emplace(std::move(key), std::move(value));
_contentType = to_ContentType(value);
if (_contentType != ContentType::Custom) {
return;
}
}
this->_meta.emplace(std::move(key), std::move(value));
}

void MessageHeader::addMeta(StringMap const& map) {
Expand Down
11 changes: 7 additions & 4 deletions 3rdParty/fuerte/src/vst.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,13 @@ void message::requestHeader(RequestHeader const& header,
// 6 - meta
{
VPackObjectBuilder guard(&builder);
builder.add(fu_accept_key, VPackValue(to_string(header.acceptType())));
builder.add(fu_content_type_key,
VPackValue(to_string(header.contentType())));
if (header.acceptType() != ContentType::Custom) {
builder.add(fu_accept_key, VPackValue(to_string(header.acceptType())));
}
if (header.contentType() != ContentType::Custom) {
builder.add(fu_content_type_key,
VPackValue(to_string(header.contentType())));
}
for (auto const& pair : header.meta()) {
if (boost::iequals(fu_content_type_key, pair.first) ||
boost::iequals(fu_accept_key, pair.first)) {
Expand All @@ -163,7 +167,6 @@ void message::requestHeader(RequestHeader const& header,
builder.add(pair.first, VPackValue(pair.second));
}
}

builder.close(); // </array>
}

Expand Down
25 changes: 20 additions & 5 deletions lib/Rest/VstResponse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,12 +124,9 @@ void VstResponse::writeMessageHeader(VPackBuffer<uint8_t>& buffer) const {
builder.add(VPackValue(int(2))); // 2 == response
builder.add(VPackValue(static_cast<int>(meta::underlyingValue(_responseCode)))); // 3 == request - return code

std::string currentHeader;
builder.openObject(); // 4 == meta
for (auto& item : _headers) {
currentHeader.assign(item.first);
auto fixCase = [](std::string& tmp) {
int capState = 1;
for (auto& it : currentHeader) {
for (auto& it : tmp) {
if (capState == 1) {
// upper case
it = ::toupper(it);
Expand All @@ -144,8 +141,26 @@ void VstResponse::writeMessageHeader(VPackBuffer<uint8_t>& buffer) const {
}
}
}
};

std::string currentHeader;
builder.openObject(); // 4 == meta
for (auto& item : _headers) {
if (_contentType != ContentType::CUSTOM &&
item.first.compare(0, StaticStrings::ContentTypeHeader.size(),
StaticStrings::ContentTypeHeader) == 0) {
continue;
}
currentHeader.assign(item.first);
fixCase(currentHeader);
builder.add(currentHeader, VPackValue(item.second));
}
if (_contentType != ContentType::VPACK &&
_contentType != ContentType::CUSTOM) { // fuerte uses VPack as default
std::string currentHeader = StaticStrings::ContentTypeHeader;
fixCase(currentHeader);
builder.add(currentHeader, VPackValue(rest::contentTypeToString(_contentType)));
}
builder.close();
builder.close();
}
0