FireBreath  1.4.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Pages
BrowserStreamRequest.h
1 /**********************************************************\
2 Original Author: Richard Bateman (taxilian)
3 
4 Created: Sep 25, 2012
5 License: Dual license model; choose one of two:
6  New BSD License
7  http://www.opensource.org/licenses/bsd-license.php
8  - or -
9  GNU Lesser General Public License, version 2.1
10  http://www.gnu.org/licenses/lgpl-2.1.html
11 
12 Copyright 2009 Richard Bateman, Firebreath development team
13 \**********************************************************/
14 #pragma once
15 #ifndef BrowserStreamRequest_h__
16 #define BrowserStreamRequest_h__
17 
18 #include "SimpleStreamHelper.h"
19 #include <string>
20 
21 #define k_DEFAULT_REQUEST_BUFFER 128 * 1024
22 
23 namespace FB {
24 
25  FB_FORWARD_PTR(PluginEventSink);
26 
39  {
40  public:
53  BrowserStreamRequest(const std::string& uri, const std::string method = "GET", const bool accept = true)
54  : uri(uri), method(method), lastModified(0), seekable(false),
55  internalBufferSize(k_DEFAULT_REQUEST_BUFFER), cache(false), accepted(accept)
56  {
57 
58  }
59 
72  BrowserStreamRequest(const FB::URI& uri, const std::string method = "GET", const bool accept = true)
73  : uri(uri), method(method), lastModified(0), seekable(false),
74  internalBufferSize(k_DEFAULT_REQUEST_BUFFER), cache(false), accepted(accept)
75  {
76 
77  }
78 
79  FB::URI uri;
80  std::string method;
81  FB::HeaderMap headers;
82  uint32_t lastModified;
83  bool seekable;
84  size_t internalBufferSize;
85  bool cache;
86 
87  private:
88  PluginEventSinkPtr sinkPtr;
89  HttpCallback callback;
90  bool accepted;
91  std::string postdata;
92  std::string postheaders;
93 
94  public: // Helper methods
104  void setSeekable(bool s) { seekable = s; }
115  void setCacheable(bool c) { cache = c; }
124  bool wasAccepted() const { return accepted; }
135  void addQueryData(const std::string& key, const std::string& val) {
136  uri.addQueryData(key, val);
137  }
147  void setHeaders(const std::string& headers) {
148  this->headers = SimpleStreamHelper::parse_http_headers(headers);
149  }
159  void setLastModified(uint32_t ts) { lastModified = ts; }
169  void setBufferSize(size_t size) { internalBufferSize = size; }
170 
187  void setEventSink(const PluginEventSinkPtr& ptr) { sinkPtr = ptr; accepted = true; }
196  PluginEventSinkPtr getEventSink() const { return sinkPtr; }
197 
216  void setCallback( const HttpCallback& cb ) { callback = cb; accepted = true; }
225  HttpCallback getCallback() const { return callback; }
226 
237  void setPostData(const std::string& data, const std::string& post_headers = "") { postdata = data; postheaders = post_headers; }
245  std::string getPostData() const { return postdata; }
253  std::string getPostHeaders() const { return postheaders; }
254  };
255 
256 };
257 
258 #endif // BrowserStreamRequest_h__
void setHeaders(const std::string &headers)
Used internally to set the headers on this object. Should not be called normally. ...
void setBufferSize(size_t size)
Call this to indicate the preferred internal buffer size of the BrowserStream object.
void setCallback(const HttpCallback &cb)
Call this method to provide a callback function that should be called when the request completes...
void setSeekable(bool s)
Call with true to request that the stream be seekable; default is false.
bool wasAccepted() const
Returns true if the request was accepted; used internally. User-created requests are accepted by defa...
Information about an HTTP request to be made.
void setLastModified(uint32_t ts)
Used internally to set the lastmodified timestamp on the object.
Data structure for dealing with URI strings.
Definition: URI.h:42
void setEventSink(const PluginEventSinkPtr &ptr)
To use a PluginEventSink such as DefaultBrowserStreamHandler or a derivative call this method to spec...
std::string getPostHeaders() const
Returns POST headers for the object, if any.
HttpCallback getCallback() const
Returns the HttpCallback functor assigned to the object, or a NULL HttpCallback if none...
PluginEventSinkPtr getEventSink() const
Returns the PluginEventSink assigned to be the observer for the BrowserStream, or a NULL BrowserStrea...
void addQueryData(const std::string &key, const std::string &val)
Add a GET querystring parameter (... &key=val ...)
std::string getPostData() const
Returns POST data for the object, if any.
void setCacheable(bool c)
Call with true to indicate that the browser's cache may be used for this request; default is false...