All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
WebRequestBuilder.h
1 // Copyright eeGeo Ltd (2012-2015), All Rights Reserved
2 
3 #pragma once
4 
5 #include "Types.h"
6 #include "Web.h"
7 #include "WebPostData.h"
8 #include "Helpers.h"
9 #include "UrlHelpers.h"
10 
11 #include <string>
12 #include <map>
13 #include <vector>
14 
15 namespace Eegeo
16 {
17  namespace Web
18  {
23  {
24  public:
26  const TWebRequestId requestId,
27  Eegeo::Web::IWebRequestService& webRequestService,
28  Helpers::IHttpCache& httpCache,
29  const Eegeo::Web::HttpVerbs::Values httpVerb,
30  const std::string& url,
33 
34  WebRequestBuilder& AddHeader(const std::string& headerFieldName, const std::string& value);
35  WebRequestBuilder& AddQueryParam(const std::string& keyName, const std::string& value);
36  WebRequestBuilder& AddFormData(const std::string& keyName, const std::string& value);
37  WebRequestBuilder& AddPostData(const std::string& keyName, const WebPostData& postData);
38 
39  WebRequestBuilder& SetUserData(void* pUserData);
40  WebRequestBuilder& SetPostBodyData(const WebPostData& bodyData);
41  WebRequestBuilder& SetUserAgent(const std::string& userAgent);
42  WebRequestBuilder& SetRetryLimit(const u32 retryLimit);
43  WebRequestBuilder& SetTimeout(const u32 timeoutInSeconds);
44 
45  WebRequestBuilder& SetShouldCacheAggressively(const bool shouldCacheAggressively);
46  WebRequestBuilder& SetShouldRequestOnlyFromCache(const bool cacheOnly);
47  WebRequestBuilder& SetShouldCacheResponse(const bool cacheResponse);
48  WebRequestBuilder& SetAllowCacheFetchWithoutHeaders(const bool allowCacheFetchWithoutHeaders);
49 
50  WebRequestBuilder& AcceptContentType(const std::string& mimeType);
51  WebRequestBuilder& AcceptBinaryContentTypes();
52  WebRequestBuilder& AcceptProxyWorkaroundBinaryContentTypes();
53  WebRequestBuilder& AcceptTextureContentTypes();
54  WebRequestBuilder& RequireResponseHeader(const std::string& requiredHeaderName);
55 
57 
58  bool HasPostBodyData();
59  private:
60  bool TryAddConditionalGetHeaders();
61 
62  Eegeo::Web::HttpVerbs::Values m_httpVerb;
63  std::string m_url;
66 
67  void* m_pUserData;
68  bool m_hasUserData;
69  std::string m_userAgent;
70  int m_retryLimit;
71  int m_timeoutInSeconds;
72  WebPostData m_postBodyData;
73  bool m_hasPostBodyData;
74  std::map<std::string, std::string> m_httpRequestHeaders;
75  std::map<std::string, WebPostData> m_httpPostData;
76  std::vector<std::string> m_acceptableMimeTypes;
77  std::vector<std::string> m_requiredResponseHeaderNames;
78 
79  TWebRequestId m_requestId;
80  Eegeo::Web::IWebRequestService* m_pWebRequestService;
81  Helpers::IHttpCache* m_pHttpCache;
82  bool m_hasBeenBuilt;
83  bool m_shouldCacheAggressively;
84  bool m_cacheOnly;
85  bool m_shouldCacheResponse;
86  bool m_allowCacheFetchWithoutHeaders;
87  };
88  }
89 }