Browse Source

send_extra_headers

David Rose 23 years ago
parent
commit
1e96f1ca63

+ 31 - 0
panda/src/downloader/httpChannel.I

@@ -383,6 +383,37 @@ reset() {
   reset_to_new();
   reset_to_new();
 }
 }
 
 
+////////////////////////////////////////////////////////////////////
+//     Function: HTTPChannel::clear_extra_headers
+//       Access: Published
+//  Description: Resets the extra headers that were previously added
+//               via calls to send_extra_header().
+////////////////////////////////////////////////////////////////////
+INLINE void HTTPChannel::
+clear_extra_headers() {
+  _send_extra_headers = string();
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: HTTPChannel::send_extra_header
+//       Access: Published
+//  Description: Specifies an additional key: value pair that is added
+//               into the header sent to the server with the next
+//               request.  This is passed along with no interpretation
+//               by the HTTPChannel code.  You may call this
+//               repeatedly to append multiple headers.
+//
+//               This is persistent for one request only; it must be
+//               set again for each new request.
+////////////////////////////////////////////////////////////////////
+INLINE void HTTPChannel::
+send_extra_header(const string &key, const string &value) {
+  _send_extra_headers += key;
+  _send_extra_headers += ": ";
+  _send_extra_headers += value;
+  _send_extra_headers += "\r\n";
+}
+
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 //     Function: HTTPChannel::get_document
 //     Function: HTTPChannel::get_document
 //       Access: Published
 //       Access: Published

+ 8 - 1
panda/src/downloader/httpChannel.cxx

@@ -202,6 +202,7 @@ write_headers(ostream &out) const {
 bool HTTPChannel::
 bool HTTPChannel::
 run() {
 run() {
   if (_state == _done_state || _state == S_failure) {
   if (_state == _done_state || _state == S_failure) {
+    clear_extra_headers();
     if (!reached_done_state()) {
     if (!reached_done_state()) {
       return false;
       return false;
     }
     }
@@ -341,6 +342,7 @@ run() {
     }
     }
 
 
     if (_state == _done_state || _state == S_failure) {
     if (_state == _done_state || _state == S_failure) {
+      clear_extra_headers();
       // We've reached our terminal state.
       // We've reached our terminal state.
       return reached_done_state();
       return reached_done_state();
     }
     }
@@ -1022,6 +1024,10 @@ run_request_sent() {
     return false;
     return false;
   }
   }
 
 
+  // Ok, we've established an HTTP connection to the server.  Our
+  // extra send headers have done their job; clear them for next time.
+  clear_extra_headers();
+
   _state = S_reading_header;
   _state = S_reading_header;
   _current_field_name = string();
   _current_field_name = string();
   _current_field_value = string();
   _current_field_value = string();
@@ -2307,7 +2313,8 @@ make_request_text() {
       _www_auth->generate(_method, _url.get_path(), _www_username, _body);
       _www_auth->generate(_method, _url.get_path(), _www_username, _body);
     _request_text += "\r\n";
     _request_text += "\r\n";
   }
   }
-    
+
+  _request_text += _send_extra_headers;
   _request_text += "\r\n";
   _request_text += "\r\n";
   _request_text += _body;
   _request_text += _body;
 }
 }

+ 4 - 0
panda/src/downloader/httpChannel.h

@@ -109,6 +109,9 @@ PUBLISHED:
 
 
   INLINE void reset();
   INLINE void reset();
 
 
+  INLINE void clear_extra_headers();
+  INLINE void send_extra_header(const string &key, const string &value);
+
   INLINE bool get_document(const URLSpec &url);
   INLINE bool get_document(const URLSpec &url);
   INLINE bool get_subdocument(const URLSpec &url, 
   INLINE bool get_subdocument(const URLSpec &url, 
                               size_t first_byte, size_t last_byte);
                               size_t first_byte, size_t last_byte);
@@ -208,6 +211,7 @@ private:
   double _seconds_per_update;
   double _seconds_per_update;
   int _bytes_per_update;
   int _bytes_per_update;
   bool _nonblocking;
   bool _nonblocking;
+  string _send_extra_headers;
 
 
   URLSpec _url;
   URLSpec _url;
   HTTPEnum::Method _method;
   HTTPEnum::Method _method;