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
Changes from 1 commit
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
Next Next commit
Fix content-type for JS APIs
  • Loading branch information
graetzer committed Oct 10, 2019
commit f04dc56ca475dd5789ada9f453904f1e2f13adc2
23 changes: 18 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,24 @@ void VstResponse::writeMessageHeader(VPackBuffer<uint8_t>& buffer) const {
}
}
}
};

std::string currentHeader;
builder.openObject(); // 4 == meta
for (auto& item : _headers) {
if (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) { // fuerte uses VPack as default
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for content type "CUSTOM" this will write Content-Type: , because rest::contentTypeToString(CUSTOM) will return an empty string. Intentional?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

perhaps we need a more comprehensive fix

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we need to store a custom content type separately, or remove the special handling of the content-type altogether and handle it like all other headers.

std::string currentHeader = StaticStrings::ContentTypeHeader;
fixCase(currentHeader);
builder.add(currentHeader, VPackValue(rest::contentTypeToString(_contentType)));
}
builder.close();
builder.close();
}
0