Remove null body stream (#1741)
* Remove LimitBodyStream Move NullBodyStream to internal
This commit is contained in:
parent
d1e43af75e
commit
5fdb9f4b5d
@ -10,6 +10,8 @@
|
||||
- Renamed `NoRevoke` to `EnableCertificateRevocationListCheck` for `Azure::Core::Http::CurlTransportSSLOptions`.
|
||||
- Renamed `GetString()` to `ToString()` in `Azure::Core::DateTime`.
|
||||
- Renamed `GetUuidString()` tp `ToString()` in `Azure::Core::Uuid`.
|
||||
- Moved `NullBodyStream` to internal usage only. It is not meant for public use.
|
||||
- Removed `LimitBodyStream`.
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
|
||||
@ -52,6 +52,7 @@ set(
|
||||
inc/azure/core/http/transport.hpp
|
||||
inc/azure/core/internal/contract.hpp
|
||||
inc/azure/core/internal/hkeyholder.hpp
|
||||
inc/azure/core/internal/http/null_body_stream.hpp
|
||||
inc/azure/core/internal/http/pipeline.hpp
|
||||
inc/azure/core/internal/json_serializable.hpp
|
||||
inc/azure/core/internal/json.hpp
|
||||
|
||||
@ -160,38 +160,6 @@ namespace Azure { namespace Core { namespace Http {
|
||||
void Rewind() override { m_offset = 0; }
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Empty #Azure::Core::Http::BodyStream.
|
||||
* @remark Used for requests with no body.
|
||||
*/
|
||||
class NullBodyStream : public Azure::Core::Http::BodyStream {
|
||||
private:
|
||||
int64_t OnRead(Azure::Core::Context const& context, uint8_t* buffer, int64_t count) override
|
||||
{
|
||||
(void)context;
|
||||
(void)buffer;
|
||||
(void)count;
|
||||
return 0;
|
||||
};
|
||||
|
||||
public:
|
||||
/// Constructor.
|
||||
explicit NullBodyStream() {}
|
||||
|
||||
int64_t Length() const override { return 0; }
|
||||
|
||||
void Rewind() override {}
|
||||
|
||||
/**
|
||||
* @brief Gets a singleton instance of a #Azure::Core::Http::NullBodyStream.
|
||||
*/
|
||||
static NullBodyStream* GetNullBodyStream()
|
||||
{
|
||||
static NullBodyStream nullBodyStream;
|
||||
return &nullBodyStream;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief #Azure::Core::Http::BodyStream providing its data from a file.
|
||||
*/
|
||||
@ -243,36 +211,4 @@ namespace Azure { namespace Core { namespace Http {
|
||||
int64_t Length() const override { return this->m_length; };
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief #Azure::Core::Http::BodyStream that provides its data from another
|
||||
* #Azure::Core::Http::BodyStream.
|
||||
*/
|
||||
class LimitBodyStream : public BodyStream {
|
||||
private:
|
||||
BodyStream* m_inner;
|
||||
int64_t m_length;
|
||||
int64_t m_bytesRead = 0;
|
||||
|
||||
int64_t OnRead(Context const& context, uint8_t* buffer, int64_t count) override;
|
||||
|
||||
public:
|
||||
/**
|
||||
* @brief Construct from another #Azure::Core::Http::BodyStream.
|
||||
*
|
||||
* @param inner #Azure::Core::Http::BodyStream to provide the data from to the readers.
|
||||
* @param max_length Maximum number of bytes to provide to the readers.
|
||||
*/
|
||||
LimitBodyStream(BodyStream* inner, int64_t max_length)
|
||||
: m_inner(inner), m_length((std::min)(inner->Length(), max_length))
|
||||
{
|
||||
}
|
||||
|
||||
int64_t Length() const override { return this->m_length; }
|
||||
void Rewind() override
|
||||
{
|
||||
this->m_inner->Rewind();
|
||||
this->m_bytesRead = 0;
|
||||
}
|
||||
};
|
||||
|
||||
}}} // namespace Azure::Core::Http
|
||||
|
||||
@ -499,14 +499,7 @@ namespace Azure { namespace Core { namespace Http {
|
||||
* @param downloadViaStream A boolean value indicating whether download should happen via
|
||||
* stream.
|
||||
*/
|
||||
explicit Request(HttpMethod httpMethod, Url url, bool downloadViaStream)
|
||||
: Request(
|
||||
httpMethod,
|
||||
std::move(url),
|
||||
NullBodyStream::GetNullBodyStream(),
|
||||
downloadViaStream)
|
||||
{
|
||||
}
|
||||
explicit Request(HttpMethod httpMethod, Url url, bool downloadViaStream);
|
||||
|
||||
/**
|
||||
* @brief Construct an #Azure::Core::Http::Request.
|
||||
@ -514,10 +507,7 @@ namespace Azure { namespace Core { namespace Http {
|
||||
* @param httpMethod HTTP method.
|
||||
* @param url URL.
|
||||
*/
|
||||
explicit Request(HttpMethod httpMethod, Url url)
|
||||
: Request(httpMethod, std::move(url), NullBodyStream::GetNullBodyStream(), false)
|
||||
{
|
||||
}
|
||||
explicit Request(HttpMethod httpMethod, Url url);
|
||||
|
||||
/**
|
||||
* @brief Add HTTP header to the #Azure::Core::Http::Request.
|
||||
|
||||
@ -0,0 +1,47 @@
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
/**
|
||||
* @file
|
||||
* @brief A null body stream for Http requests without a payload.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "azure/core/http/body_stream.hpp"
|
||||
|
||||
namespace Azure { namespace Core { namespace Internal { namespace Http {
|
||||
|
||||
/**
|
||||
* @brief Empty #Azure::Core::Http::BodyStream.
|
||||
* @remark Used for requests with no body.
|
||||
*/
|
||||
class NullBodyStream : public Azure::Core::Http::BodyStream {
|
||||
private:
|
||||
int64_t OnRead(Azure::Core::Context const& context, uint8_t* buffer, int64_t count) override
|
||||
{
|
||||
(void)context;
|
||||
(void)buffer;
|
||||
(void)count;
|
||||
return 0;
|
||||
};
|
||||
|
||||
public:
|
||||
/// Constructor.
|
||||
explicit NullBodyStream() {}
|
||||
|
||||
int64_t Length() const override { return 0; }
|
||||
|
||||
void Rewind() override {}
|
||||
|
||||
/**
|
||||
* @brief Gets a singleton instance of a #Azure::Core::Http::NullBodyStream.
|
||||
*/
|
||||
static NullBodyStream* GetNullBodyStream()
|
||||
{
|
||||
static NullBodyStream nullBodyStream;
|
||||
return &nullBodyStream;
|
||||
}
|
||||
};
|
||||
|
||||
}}}} // namespace Azure::Core::Internal::Http
|
||||
@ -133,13 +133,3 @@ int64_t FileBodyStream::OnRead(Azure::Core::Context const& context, uint8_t* buf
|
||||
return numberOfBytesRead;
|
||||
}
|
||||
#endif
|
||||
|
||||
int64_t LimitBodyStream::OnRead(Context const& context, uint8_t* buffer, int64_t count)
|
||||
{
|
||||
(void)context;
|
||||
// Read up to count or whatever length is remaining; whichever is less
|
||||
uint64_t bytesRead
|
||||
= m_inner->Read(context, buffer, std::min(count, this->m_length - this->m_bytesRead));
|
||||
this->m_bytesRead += bytesRead;
|
||||
return bytesRead;
|
||||
}
|
||||
|
||||
@ -2,9 +2,13 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
#include "azure/core/http/http.hpp"
|
||||
#include "azure/core/internal/http/null_body_stream.hpp"
|
||||
|
||||
#include <utility>
|
||||
|
||||
using namespace Azure::Core::Http;
|
||||
using namespace Azure::Core::Internal::Http;
|
||||
|
||||
void Azure::Core::Http::Details::InsertHeaderWithValidation(
|
||||
std::map<std::string, std::string>& headers,
|
||||
std::string const& headerName,
|
||||
@ -155,3 +159,13 @@ void Azure::Core::Http::Details::InsertHeaderWithValidation(
|
||||
// insert (override if duplicated)
|
||||
headers[headerName] = headerValue;
|
||||
}
|
||||
|
||||
Request::Request(HttpMethod httpMethod, Url url, bool downloadViaStream)
|
||||
: Request(httpMethod, std::move(url), NullBodyStream::GetNullBodyStream(), downloadViaStream)
|
||||
{
|
||||
}
|
||||
|
||||
Request::Request(HttpMethod httpMethod, Url url)
|
||||
: Request(httpMethod, std::move(url), NullBodyStream::GetNullBodyStream(), false)
|
||||
{
|
||||
}
|
||||
|
||||
@ -5,6 +5,7 @@
|
||||
|
||||
#include "http.hpp"
|
||||
#include <azure/core/http/http.hpp>
|
||||
#include <azure/core/internal/http/null_body_stream.hpp>
|
||||
|
||||
#include <string>
|
||||
#include <utility>
|
||||
@ -167,8 +168,8 @@ namespace Azure { namespace Core { namespace Test {
|
||||
Http::Url url("http://test.com");
|
||||
Http::Request req(httpMethod, url);
|
||||
|
||||
Azure::Core::Http::NullBodyStream* d
|
||||
= dynamic_cast<Azure::Core::Http::NullBodyStream*>(req.GetBodyStream());
|
||||
Azure::Core::Internal::Http::NullBodyStream* d
|
||||
= dynamic_cast<Azure::Core::Internal::Http::NullBodyStream*>(req.GetBodyStream());
|
||||
EXPECT_TRUE(d);
|
||||
|
||||
req.StartTry();
|
||||
@ -184,7 +185,7 @@ namespace Azure { namespace Core { namespace Test {
|
||||
|
||||
EXPECT_FALSE(headers.count("name"));
|
||||
|
||||
d = dynamic_cast<Azure::Core::Http::NullBodyStream*>(req.GetBodyStream());
|
||||
d = dynamic_cast<Azure::Core::Internal::Http::NullBodyStream*>(req.GetBodyStream());
|
||||
EXPECT_TRUE(d);
|
||||
}
|
||||
|
||||
|
||||
@ -5,6 +5,7 @@
|
||||
|
||||
#include <azure/core/credentials.hpp>
|
||||
#include <azure/core/http/policy.hpp>
|
||||
#include <azure/core/internal/http/null_body_stream.hpp>
|
||||
#include <azure/storage/common/concurrent_transfer.hpp>
|
||||
#include <azure/storage/common/constants.hpp>
|
||||
#include <azure/storage/common/crypt.hpp>
|
||||
@ -512,7 +513,7 @@ namespace Azure { namespace Storage { namespace Files { namespace Shares {
|
||||
protocolLayerOptions.LeaseIdOptional = options.AccessConditions.LeaseId;
|
||||
auto response = Details::ShareRestClient::File::UploadRange(
|
||||
m_shareFileUrl,
|
||||
*Azure::Core::Http::NullBodyStream::GetNullBodyStream(),
|
||||
*Azure::Core::Internal::Http::NullBodyStream::GetNullBodyStream(),
|
||||
*m_pipeline,
|
||||
context,
|
||||
protocolLayerOptions);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user