Skip to content

Commit

Permalink
Fix bug introduced in previous PR #1638 (#1641)
Browse files Browse the repository at this point in the history
In `HttpConnection::multipartProducer()` the `IDataSourceStream*` entry from `files` must be extracted, not removed
Add `extractAt()` method added to `ObjectMap` to support this operation more efficiently
  • Loading branch information
mikee47 authored and slaff committed Feb 25, 2019
1 parent 9079572 commit b8f7d1f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
21 changes: 16 additions & 5 deletions Sming/SmingCore/Data/ObjectMap.h
Original file line number Diff line number Diff line change
Expand Up @@ -287,12 +287,23 @@ template <typename K, typename V> class ObjectMap
*/
V* extract(const K& key)
{
V* value = nullptr;
int i = indexOf(key);
if(i >= 0) {
value = entries[i].value;
entries[i].value = nullptr;
entries.remove(i);
return (i < 0) ? nullptr : extractAt(i);
}

/**
* @brief Get the value at a given index and remove it from the map, without destroying it
* @param index
* @retval V*
* @note The returned object must be freed by the caller when no longer required
*/
V* extractAt(unsigned index)
{
V* value = nullptr;
if(index < entries.count()) {
value = entries[index].value;
entries[index].value = nullptr;
entries.remove(index);
}
return value;
}
Expand Down
3 changes: 1 addition & 2 deletions Sming/SmingCore/Network/Http/HttpConnection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ HttpPartResult HttpConnection::multipartProducer()

if(outgoingRequest->files.count()) {
String name = outgoingRequest->files.keyAt(0);
auto file = outgoingRequest->files[name];
auto file = outgoingRequest->files.extractAt(0);
result.stream = file;

HttpHeaders* headers = new HttpHeaders();
Expand All @@ -124,7 +124,6 @@ HttpPartResult HttpConnection::multipartProducer()
(*headers)[HTTP_HEADER_CONTENT_TYPE] = ContentType::fromFullFileName(file->getName());
result.headers = headers;

outgoingRequest->files.remove(name);
return result;
}

Expand Down

0 comments on commit b8f7d1f

Please sign in to comment.