AlexaClientSDK  3.0.0
A cross-platform, modular SDK for interacting with the Alexa Voice Service
Classes | Public Types | Public Member Functions | Static Public Member Functions | List of all members
alexaClientSDK::avsCommon::sdkInterfaces::HTTPContentFetcherInterface Class Referenceabstract

#include <HTTPContentFetcherInterface.h>

Inheritance diagram for alexaClientSDK::avsCommon::sdkInterfaces::HTTPContentFetcherInterface:
Inheritance graph


struct  Header

Public Types

enum  FetchOptions { FetchOptions::CONTENT_TYPE, FetchOptions::ENTIRE_BODY }
 Represents what HTTP content to fetch. More...
enum  State {
  State::BODY_DONE, State::ERROR
 The state of payload fetching. More...

Public Member Functions

virtual ~HTTPContentFetcherInterface ()=default
virtual State getState ()=0
virtual std::string getUrl () const =0
virtual std::string getEffectiveUrl () const =0
virtual Header getHeader (std::atomic< bool > *shouldShutdown)=0
virtual bool getBody (std::shared_ptr< avsCommon::avs::attachment::AttachmentWriter > writer)=0
virtual void shutdown ()=0
virtual std::unique_ptr< avsCommon::utils::HTTPContentgetContent (FetchOptions option, std::unique_ptr< avsCommon::avs::attachment::AttachmentWriter > writer=nullptr, const std::vector< std::string > &customHeaders=std::vector< std::string >())=0

Static Public Member Functions

static std::string getUserAgent ()
static std::string stateToString (State state)

Detailed Description

This class allows users to fetch content from remote location using HTTP(S).

Member Enumeration Documentation

◆ FetchOptions

Represents what HTTP content to fetch.


Retrieves the content type part of the HTTP header.


Retrieves the entire body of the remote location.

◆ State

The state of payload fetching.


Initialized but nothing was downloaded yet.


Currently fetching the header.


Done fetching the header. Ready to start fetching the body.


Currently fetching the body.


Done fetching the body. At this point the content fetcher can only be used to read the headers.


Some error happened at any stage and the content fetcher cannot be used anymore.

Constructor & Destructor Documentation

◆ ~HTTPContentFetcherInterface()

virtual alexaClientSDK::avsCommon::sdkInterfaces::HTTPContentFetcherInterface::~HTTPContentFetcherInterface ( )


Member Function Documentation

◆ getBody()

virtual bool alexaClientSDK::avsCommon::sdkInterfaces::HTTPContentFetcherInterface::getBody ( std::shared_ptr< avsCommon::avs::attachment::AttachmentWriter writer)
pure virtual

Retrieves the body after the header was received. This method is asynchronous and the caller can monitor the download progress using the getState method.

writerThe writer to write the payload.
true if the call is successful.

◆ getContent()

virtual std::unique_ptr<avsCommon::utils::HTTPContent> alexaClientSDK::avsCommon::sdkInterfaces::HTTPContentFetcherInterface::getContent ( FetchOptions  option,
std::unique_ptr< avsCommon::avs::attachment::AttachmentWriter writer = nullptr,
const std::vector< std::string > &  customHeaders = std::vector< std::string >() 
pure virtual

This function retrieves content from a remote location. No thread safety is guaranteed.

optionFlag indicating desired content.
writerAn optional writer parameter to be used when writing to an external stream.
customHeadersAn optional list of headers to be attached to the request.
A new HTTPContent object or nullptr if a failure occurred.

◆ getEffectiveUrl()

virtual std::string alexaClientSDK::avsCommon::sdkInterfaces::HTTPContentFetcherInterface::getEffectiveUrl ( ) const
pure virtual

Gets the effective URL associated with this content fetcher.

This is useful in the case of redirects where the first URL used redirects to a different URL to fetch the content.
The content fetcher's effective URL.

Implemented in alexaClientSDK::playlistParser::test::MockContentFetcher, alexaClientSDK::mediaPlayer::test::MockContentFetcher, and alexaClientSDK::avsCommon::utils::libcurlUtils::LibCurlHttpContentFetcher.

◆ getHeader()

virtual Header alexaClientSDK::avsCommon::sdkInterfaces::HTTPContentFetcherInterface::getHeader ( std::atomic< bool > *  shouldShutdown)
pure virtual

Waits until the header was fetched successfully. If any problem happened during header, returns false. After the header was already fetched, this method can be called multiple times and will return immediately.

shouldShutdownA pointer to allow for the caller to asynchronously cancel the wait, if needed. this argument is optional. If it is a null pointer, the function will ignore it.
The header struct. It is the caller's responsibility to check the struct to see if the header was retrieved successfully.

Implemented in alexaClientSDK::playlistParser::test::MockContentFetcher, alexaClientSDK::mediaPlayer::test::MockContentFetcher, and alexaClientSDK::avsCommon::utils::libcurlUtils::LibCurlHttpContentFetcher.

◆ getState()

virtual State alexaClientSDK::avsCommon::sdkInterfaces::HTTPContentFetcherInterface::getState ( )
pure virtual

The current content fetching state. In particular, a caller of getBody, an asynchronous function, can use this method to monitor the download progress.

The current content fetching state.

Implemented in alexaClientSDK::playlistParser::test::MockContentFetcher, alexaClientSDK::mediaPlayer::test::MockContentFetcher, and alexaClientSDK::avsCommon::utils::libcurlUtils::LibCurlHttpContentFetcher.

◆ getUrl()

virtual std::string alexaClientSDK::avsCommon::sdkInterfaces::HTTPContentFetcherInterface::getUrl ( ) const
pure virtual

◆ getUserAgent()

std::string alexaClientSDK::avsCommon::sdkInterfaces::HTTPContentFetcherInterface::getUserAgent ( )

Returns a string that represents the User-Agent to be used in HTTP requests.

User-Agent string to be used in HTTP requests.

◆ shutdown()

virtual void alexaClientSDK::avsCommon::sdkInterfaces::HTTPContentFetcherInterface::shutdown ( )
pure virtual

◆ stateToString()

std::string alexaClientSDK::avsCommon::sdkInterfaces::HTTPContentFetcherInterface::stateToString ( HTTPContentFetcherInterface::State  state)

Produces the string representation of the state enum values.

stateThe state enum value.
Its string representation.

The documentation for this class was generated from the following file:

AlexaClientSDK 3.0.0 - Copyright 2016-2022, Inc. or its affiliates. All Rights Reserved. Licensed under the Apache License, Version 2.0