balsa_headers.h revision 731df977c0511bca2206b5f333555b1205ff1f43
1// Copyright (c) 2009 The Chromium Authors. All rights reserved. 2// Use of this source code is governed by a BSD-style license that can be 3// found in the LICENSE file. 4 5#ifndef NET_TOOLS_FLIP_SERVER_BALSA_HEADERS_H_ 6#define NET_TOOLS_FLIP_SERVER_BALSA_HEADERS_H_ 7#pragma once 8 9#include <algorithm> 10#include <iosfwd> 11#include <iterator> 12#include <string> 13#include <utility> 14#include <vector> 15 16#include "base/port.h" 17#include "base/logging.h" 18#include "base/string_piece.h" 19#include "net/tools/flip_server/balsa_enums.h" 20#include "net/tools/flip_server/string_piece_utils.h" 21 22namespace net { 23 24// WARNING: 25// Note that -no- char* returned by any function in this 26// file is null-terminated. 27 28// This class exists to service the specific needs of BalsaHeaders. 29// 30// Functional goals: 31// 1) provide a backing-store for all of the StringPieces that BalsaHeaders 32// returns. Every StringPiece returned from BalsaHeaders should remain 33// valid until the BalsaHeader's object is cleared, or the header-line is 34// erased. 35// 2) provide a backing-store for BalsaFrame, which requires contiguous memory 36// for its fast-path parsing functions. Note that the cost of copying is 37// less than the cost of requiring the parser to do slow-path parsing, as 38// it would have to check for bounds every byte, instead of every 16 bytes. 39// 40// This class is optimized for the case where headers are stored in one of two 41// buffers. It doesn't make a lot of effort to densely pack memory-- in fact, 42// it -may- be somewhat memory inefficient. This possible inefficiency allows a 43// certain simplicity of implementation and speed which makes it worthwhile. 44// If, in the future, better memory density is required, it should be possible 45// to reuse the abstraction presented by this object to achieve those goals. 46// 47// In the most common use-case, this memory inefficiency should be relatively 48// small. 49// 50// Alternate implementations of BalsaBuffer may include: 51// - vector of strings, one per header line (similar to HTTPHeaders) 52// - densely packed strings: 53// - keep a sorted array/map of free-space linked lists or numbers. 54// - use the entry that most closely first your needs. 55// - at this point, perhaps just use a vector of strings, and let 56// the allocator do the right thing. 57// 58class BalsaBuffer { 59 public: 60 static const size_t kDefaultBlocksize = 4096; 61 // We have two friends here. These exist as friends as we 62 // want to allow access to the constructors for the test 63 // class and the Balsa* classes. We put this into the 64 // header file as we want this class to be inlined into the 65 // BalsaHeaders implementation, yet be testable. 66 friend class BalsaBufferTestSpouse; 67 friend class BalsaHeaders; 68 69 // The BufferBlock is a structure used internally by the 70 // BalsaBuffer class to store the base buffer pointers to 71 // each block, as well as the important metadata for buffer 72 // sizes and bytes free. 73 struct BufferBlock { 74 public: 75 char* buffer; 76 size_t buffer_size; 77 size_t bytes_free; 78 79 size_t bytes_used() const { 80 return buffer_size - bytes_free; 81 } 82 char* start_of_unused_bytes() const { 83 return buffer + bytes_used(); 84 } 85 86 BufferBlock() : buffer(NULL), buffer_size(0), bytes_free(0) {} 87 ~BufferBlock() {} 88 89 BufferBlock(char* buf, size_t size, size_t free) : 90 buffer(buf), buffer_size(size), bytes_free(free) {} 91 // Yes we want this to be copyable (it gets stuck into vectors). 92 // For this reason, we don't use scoped ptrs, etc. here-- it 93 // is more efficient to manage this memory externally to this 94 // object. 95 }; 96 97 typedef std::vector<BufferBlock> Blocks; 98 99 ~BalsaBuffer() { 100 CleanupBlocksStartingFrom(0); 101 } 102 103 // Returns the total amount of memory used by the buffer blocks. 104 size_t GetTotalBufferBlockSize() const { 105 size_t buffer_size = 0; 106 for (Blocks::const_iterator iter = blocks_.begin(); 107 iter != blocks_.end(); 108 ++iter) { 109 buffer_size += iter->buffer_size; 110 } 111 return buffer_size; 112 } 113 114 const char* GetPtr(Blocks::size_type block_idx) const { 115 DCHECK_LT(block_idx, blocks_.size()) 116 << block_idx << ", " << blocks_.size(); 117 return blocks_[block_idx].buffer; 118 } 119 120 char* GetPtr(Blocks::size_type block_idx) { 121 DCHECK_LT(block_idx, blocks_.size()) 122 << block_idx << ", " << blocks_.size(); 123 return blocks_[block_idx].buffer; 124 } 125 126 // This function is different from Write(), as it ensures that the data 127 // stored via subsequent calls to this function are all contiguous (and in 128 // the order in which these writes happened). This is essentially the same 129 // as a string append. 130 // 131 // You may call this function at any time between object 132 // construction/Clear(), and the calling of the 133 // NoMoreWriteToContiguousBuffer() function. 134 // 135 // You must not call this function after the NoMoreWriteToContiguousBuffer() 136 // function is called, unless a Clear() has been called since. 137 // If you do, the program will abort(). 138 // 139 // This condition is placed upon this code so that calls to Write() can 140 // append to the buffer in the first block safely, and without invaliding 141 // the StringPiece which it returns. 142 // 143 // This function's main intended user is the BalsaFrame class, which, 144 // for reasons of efficiency, requires that the buffer from which it parses 145 // the headers be contiguous. 146 // 147 void WriteToContiguousBuffer(const base::StringPiece& sp) { 148 if (sp.empty()) { 149 return; 150 } 151 CHECK(can_write_to_contiguous_buffer_); 152 DCHECK_GE(blocks_.size(), 1u); 153 if (blocks_[0].buffer == NULL && sp.size() <= blocksize_) { 154 blocks_[0] = AllocBlock(); 155 memcpy(blocks_[0].start_of_unused_bytes(), sp.data(), sp.size()); 156 } else if (blocks_[0].bytes_free < sp.size()) { 157 // the first block isn't big enough, resize it. 158 const size_t old_storage_size_used = blocks_[0].bytes_used(); 159 const size_t new_storage_size = old_storage_size_used + sp.size(); 160 char* new_storage = new char[new_storage_size]; 161 char* old_storage = blocks_[0].buffer; 162 if (old_storage_size_used) { 163 memcpy(new_storage, old_storage, old_storage_size_used); 164 } 165 memcpy(new_storage + old_storage_size_used, sp.data(), sp.size()); 166 blocks_[0].buffer = new_storage; 167 blocks_[0].bytes_free = sp.size(); 168 blocks_[0].buffer_size = new_storage_size; 169 delete[] old_storage; 170 } else { 171 memcpy(blocks_[0].start_of_unused_bytes(), sp.data(), sp.size()); 172 } 173 blocks_[0].bytes_free -= sp.size(); 174 } 175 176 void NoMoreWriteToContiguousBuffer() { 177 can_write_to_contiguous_buffer_ = false; 178 } 179 180 // Takes a StringPiece and writes it to "permanent" storage, then returns a 181 // StringPiece which points to that data. If block_idx != NULL, it will be 182 // assigned the index of the block into which the data was stored. 183 // Note that the 'permanent' storage in which it stores data may be in 184 // the first block IFF the NoMoreWriteToContiguousBuffer function has 185 // been called since the last Clear/Construction. 186 base::StringPiece Write(const base::StringPiece& sp, 187 Blocks::size_type* block_buffer_idx) { 188 if (sp.empty()) { 189 return sp; 190 } 191 char* storage = Reserve(sp.size(), block_buffer_idx); 192 memcpy(storage, sp.data(), sp.size()); 193 return base::StringPiece(storage, sp.size()); 194 } 195 196 // Reserves "permanent" storage of the size indicated. Returns a pointer to 197 // the beginning of that storage, and assigns the index of the block used to 198 // block_buffer_idx. This function uses the first block IFF the 199 // NoMoreWriteToContiguousBuffer function has been called since the last 200 // Clear/Construction. 201 char* Reserve(size_t size, 202 Blocks::size_type* block_buffer_idx) { 203 // There should always be a 'first_block', even if it 204 // contains nothing. 205 DCHECK_GE(blocks_.size(), 1u); 206 BufferBlock* block = NULL; 207 Blocks::size_type block_idx = can_write_to_contiguous_buffer_ ? 1 : 0; 208 for (; block_idx < blocks_.size(); ++block_idx) { 209 if (blocks_[block_idx].bytes_free >= size) { 210 block = &blocks_[block_idx]; 211 break; 212 } 213 } 214 if (block == NULL) { 215 if (blocksize_ < size) { 216 blocks_.push_back(AllocCustomBlock(size)); 217 } else { 218 blocks_.push_back(AllocBlock()); 219 } 220 block = &blocks_.back(); 221 } 222 223 char* storage = block->start_of_unused_bytes(); 224 block->bytes_free -= size; 225 if (block_buffer_idx) { 226 *block_buffer_idx = block_idx; 227 } 228 return storage; 229 } 230 231 void Clear() { 232 CHECK(!blocks_.empty()); 233 if (blocksize_ == blocks_[0].buffer_size) { 234 CleanupBlocksStartingFrom(1); 235 blocks_[0].bytes_free = blocks_[0].buffer_size; 236 } else { 237 CleanupBlocksStartingFrom(0); 238 blocks_.push_back(AllocBlock()); 239 } 240 DCHECK_GE(blocks_.size(), 1u); 241 can_write_to_contiguous_buffer_ = true; 242 } 243 244 void Swap(BalsaBuffer* b) { 245 blocks_.swap(b->blocks_); 246 std::swap(can_write_to_contiguous_buffer_, 247 b->can_write_to_contiguous_buffer_); 248 std::swap(blocksize_, b->blocksize_); 249 } 250 251 void CopyFrom(const BalsaBuffer& b) { 252 CleanupBlocksStartingFrom(0); 253 blocks_.resize(b.blocks_.size()); 254 for (Blocks::size_type i = 0; i < blocks_.size(); ++i) { 255 blocks_[i] = CopyBlock(b.blocks_[i]); 256 } 257 blocksize_ = b.blocksize_; 258 can_write_to_contiguous_buffer_ = b.can_write_to_contiguous_buffer_; 259 } 260 261 const char* StartOfFirstBlock() const { 262 return blocks_[0].buffer; 263 } 264 265 const char* EndOfFirstBlock() const { 266 return blocks_[0].buffer + blocks_[0].bytes_used(); 267 } 268 269 bool can_write_to_contiguous_buffer() const { 270 return can_write_to_contiguous_buffer_; 271 } 272 size_t blocksize() const { return blocksize_; } 273 Blocks::size_type num_blocks() const { return blocks_.size(); } 274 size_t buffer_size(size_t idx) const { return blocks_[idx].buffer_size; } 275 size_t bytes_used(size_t idx) const { return blocks_[idx].bytes_used(); } 276 277 protected: 278 BalsaBuffer() : 279 blocksize_(kDefaultBlocksize), can_write_to_contiguous_buffer_(true) { 280 blocks_.push_back(AllocBlock()); 281 } 282 283 explicit BalsaBuffer(size_t blocksize) : 284 blocksize_(blocksize), can_write_to_contiguous_buffer_(true) { 285 blocks_.push_back(AllocBlock()); 286 } 287 288 BufferBlock AllocBlock() { 289 return AllocCustomBlock(blocksize_); 290 } 291 292 BufferBlock AllocCustomBlock(size_t blocksize) { 293 return BufferBlock(new char[blocksize], blocksize, blocksize); 294 } 295 296 BufferBlock CopyBlock(const BufferBlock& b) { 297 BufferBlock block = b; 298 if (b.buffer == NULL) { 299 return block; 300 } 301 302 block.buffer = new char[b.buffer_size]; 303 memcpy(block.buffer, b.buffer, b.bytes_used()); 304 return block; 305 } 306 307 // Cleans up the object. 308 // The block at start_idx, and all subsequent blocks 309 // will be cleared and have associated memory deleted. 310 void CleanupBlocksStartingFrom(Blocks::size_type start_idx) { 311 for (Blocks::size_type i = start_idx; i < blocks_.size(); ++i) { 312 delete[] blocks_[i].buffer; 313 } 314 blocks_.resize(start_idx); 315 } 316 317 // A container of BufferBlocks 318 Blocks blocks_; 319 320 // The default allocation size for a block. 321 // In general, blocksize_ bytes will be allocated for 322 // each buffer. 323 size_t blocksize_; 324 325 // If set to true, then the first block cannot be used for Write() calls as 326 // the WriteToContiguous... function will modify the base pointer for this 327 // block, and the Write() calls need to be sure that the base pointer will 328 // not be changing in order to provide the user with StringPieces which 329 // continue to be valid. 330 bool can_write_to_contiguous_buffer_; 331}; 332 333//////////////////////////////////////////////////////////////////////////////// 334 335// All of the functions in the BalsaHeaders class use string pieces, by either 336// using the StringPiece class, or giving an explicit size and char* (as these 337// are the native representation for these string pieces). 338// This is done for several reasons. 339// 1) This minimizes copying/allocation/deallocation as compared to using 340// string parameters 341// 2) This reduces the number of strlen() calls done (as the length of any 342// string passed in is relatively likely to be known at compile time, and for 343// those strings passed back we obviate the need for a strlen() to determine 344// the size of new storage allocations if a new allocation is required. 345// 3) This class attempts to store all of its data in two linear buffers in 346// order to enhance the speed of parsing and writing out to a buffer. As a 347// result, many string pieces are -not- terminated by '\0', and are not 348// c-strings. Since this is the case, we must delineate the length of the 349// string explicitly via a length. 350// 351// WARNING: The side effect of using StringPiece is that if the underlying 352// buffer changes (due to modifying the headers) the StringPieces which point 353// to the data which was modified, may now contain "garbage", and should not 354// be dereferenced. 355// For example, If you fetch some component of the first-line, (request or 356// response), and then you modify the first line, the StringPieces you 357// originally received from the original first-line may no longer be valid). 358// 359// StringPieces pointing to pieces of header lines which have not been 360// erased() or modified should be valid until the object is cleared or 361// destroyed. 362 363class BalsaHeaders { 364 public: 365 struct HeaderLineDescription { 366 HeaderLineDescription(size_t first_character_index, 367 size_t key_end_index, 368 size_t value_begin_index, 369 size_t last_character_index, 370 size_t buffer_base_index) : 371 first_char_idx(first_character_index), 372 key_end_idx(key_end_index), 373 value_begin_idx(value_begin_index), 374 last_char_idx(last_character_index), 375 buffer_base_idx(buffer_base_index), 376 skip(false) {} 377 378 HeaderLineDescription() : 379 first_char_idx(0), 380 key_end_idx(0), 381 value_begin_idx(0), 382 last_char_idx(0), 383 buffer_base_idx(0), 384 skip(false) {} 385 386 size_t first_char_idx; 387 size_t key_end_idx; 388 size_t value_begin_idx; 389 size_t last_char_idx; 390 BalsaBuffer::Blocks::size_type buffer_base_idx; 391 bool skip; 392 }; 393 394 typedef std::vector<base::StringPiece> HeaderTokenList; 395 friend bool net::ParseHTTPFirstLine(const char* begin, 396 const char* end, 397 bool is_request, 398 size_t max_request_uri_length, 399 BalsaHeaders* headers, 400 BalsaFrameEnums::ErrorCode* error_code); 401 402 protected: 403 typedef std::vector<HeaderLineDescription> HeaderLines; 404 405 // Why these base classes (iterator_base, reverse_iterator_base)? Well, if 406 // we do want to export both iterator and const_iterator types (currently we 407 // only have const_iterator), then this is useful to avoid code duplication. 408 // Additionally, having this base class makes comparisons of iterators of 409 // different types (they're different types to ensure that operator= and 410 // constructors do not work in the places where they're expected to not work) 411 // work properly. There could be as many as 4 iterator types, all based on 412 // the same data as iterator_base... so it makes sense to simply have some 413 // base classes. 414 415 class iterator_base { 416 public: 417 friend class BalsaHeaders; 418 friend class reverse_iterator_base; 419 typedef std::pair<base::StringPiece, base::StringPiece> StringPiecePair; 420 typedef StringPiecePair value_type; 421 typedef value_type& reference; 422 typedef value_type* pointer; 423 424 typedef std::forward_iterator_tag iterator_category; 425 typedef ptrdiff_t difference_type; 426 427 typedef iterator_base self; 428 429 // default constructor. 430 iterator_base() : headers_(NULL), idx_(0) { } 431 432 // copy constructor. 433 iterator_base(const iterator_base& it) 434 : headers_(it.headers_), 435 idx_(it.idx_) {} 436 437 reference operator*() const { 438 return Lookup(idx_); 439 } 440 441 pointer operator->() const { 442 return &(this->operator*()); 443 } 444 445 bool operator==(const self& it) const { 446 return idx_ == it.idx_; 447 } 448 449 bool operator<(const self& it) const { 450 return idx_ < it.idx_; 451 } 452 453 bool operator<=(const self& it) const { 454 return idx_ <= it.idx_; 455 } 456 457 bool operator!=(const self& it) const { 458 return !(*this == it); 459 } 460 461 bool operator>(const self& it) const { 462 return it < *this; 463 } 464 465 bool operator>=(const self& it) const { 466 return it <= *this; 467 } 468 469 // This mainly exists so that we can have interesting output for 470 // unittesting. The EXPECT_EQ, EXPECT_NE functions require that 471 // operator<< work for the classes it sees. It would be better if there 472 // was an additional traits-like system for the gUnit output... but oh 473 // well. 474 std::ostream& operator<<(std::ostream& os) const; 475 476 protected: 477 iterator_base(const BalsaHeaders* headers, HeaderLines::size_type index) : 478 headers_(headers), 479 idx_(index) {} 480 481 void increment() { 482 const HeaderLines& header_lines = headers_->header_lines_; 483 const HeaderLines::size_type header_lines_size = header_lines.size(); 484 const HeaderLines::size_type original_idx = idx_; 485 do { 486 ++idx_; 487 } while (idx_ < header_lines_size && header_lines[idx_].skip == true); 488 // The condition below exists so that ++(end() - 1) == end(), even 489 // if there are only 'skip == true' elements between the end() iterator 490 // and the end of the vector of HeaderLineDescriptions. 491 // TODO(fenix): refactor this list so that we don't have to do 492 // linear scanning through skipped headers (and this condition is 493 // then unnecessary) 494 if (idx_ == header_lines_size) { 495 idx_ = original_idx + 1; 496 } 497 } 498 499 void decrement() { 500 const HeaderLines& header_lines = headers_->header_lines_; 501 const HeaderLines::size_type header_lines_size = header_lines.size(); 502 const HeaderLines::size_type original_idx = idx_; 503 do { 504 --idx_; 505 } while (idx_ >= 0 && 506 idx_ < header_lines_size && 507 header_lines[idx_].skip == true); 508 // The condition below exists so that --(rbegin() + 1) == rbegin(), even 509 // if there are only 'skip == true' elements between the rbegin() iterator 510 // and the beginning of the vector of HeaderLineDescriptions. 511 // TODO(fenix): refactor this list so that we don't have to do 512 // linear scanning through skipped headers (and this condition is 513 // then unnecessary) 514 if (idx_ < 0 || idx_ > header_lines_size) { 515 idx_ = original_idx - 1; 516 } 517 } 518 519 reference Lookup(HeaderLines::size_type index) const { 520 DCHECK_LT(index, headers_->header_lines_.size()); 521 const HeaderLineDescription& line = headers_->header_lines_[index]; 522 const char* stream_begin = headers_->GetPtr(line.buffer_base_idx); 523 value_ = value_type( 524 base::StringPiece(stream_begin + line.first_char_idx, 525 line.key_end_idx - line.first_char_idx), 526 base::StringPiece(stream_begin + line.value_begin_idx, 527 line.last_char_idx - line.value_begin_idx)); 528 DCHECK_GE(line.key_end_idx, line.first_char_idx); 529 DCHECK_GE(line.last_char_idx, line.value_begin_idx); 530 return value_; 531 } 532 533 const BalsaHeaders* headers_; 534 HeaderLines::size_type idx_; 535 mutable StringPiecePair value_; 536 }; 537 538 class reverse_iterator_base : public iterator_base { 539 public: 540 typedef reverse_iterator_base self; 541 typedef iterator_base::reference reference; 542 typedef iterator_base::pointer pointer; 543 using iterator_base::headers_; 544 using iterator_base::idx_; 545 546 reverse_iterator_base() : iterator_base() {} 547 548 // This constructor is no explicit purposely. 549 reverse_iterator_base(const iterator_base& it) : // NOLINT 550 iterator_base(it) { 551 } 552 553 self& operator=(const iterator_base& it) { 554 idx_ = it.idx_; 555 headers_ = it.headers_; 556 return *this; 557 } 558 559 self& operator=(const reverse_iterator_base& it) { 560 idx_ = it.idx_; 561 headers_ = it.headers_; 562 return *this; 563 } 564 565 reference operator*() const { 566 return Lookup(idx_ - 1); 567 } 568 569 pointer operator->() const { 570 return &(this->operator*()); 571 } 572 573 reverse_iterator_base(const reverse_iterator_base& it) : 574 iterator_base(it) { } 575 576 protected: 577 void increment() { 578 --idx_; 579 iterator_base::decrement(); 580 ++idx_; 581 } 582 583 void decrement() { 584 ++idx_; 585 iterator_base::increment(); 586 --idx_; 587 } 588 589 reverse_iterator_base(const BalsaHeaders* headers, 590 HeaderLines::size_type index) : 591 iterator_base(headers, index) {} 592 }; 593 594 public: 595 class const_header_lines_iterator : public iterator_base { 596 friend class BalsaHeaders; 597 public: 598 typedef const_header_lines_iterator self; 599 const_header_lines_iterator() : iterator_base() {} 600 601 const_header_lines_iterator(const const_header_lines_iterator& it) : 602 iterator_base(it.headers_, it.idx_) {} 603 604 self& operator++() { 605 iterator_base::increment(); 606 return *this; 607 } 608 609 self& operator--() { 610 iterator_base::decrement(); 611 return *this; 612 } 613 protected: 614 const_header_lines_iterator(const BalsaHeaders* headers, 615 HeaderLines::size_type index) : 616 iterator_base(headers, index) {} 617 }; 618 619 class const_reverse_header_lines_iterator : public reverse_iterator_base { 620 public: 621 typedef const_reverse_header_lines_iterator self; 622 const_reverse_header_lines_iterator() : reverse_iterator_base() {} 623 624 const_reverse_header_lines_iterator( 625 const const_header_lines_iterator& it) : 626 reverse_iterator_base(it.headers_, it.idx_) {} 627 628 const_reverse_header_lines_iterator( 629 const const_reverse_header_lines_iterator& it) : 630 reverse_iterator_base(it.headers_, it.idx_) {} 631 632 const_header_lines_iterator base() { 633 return const_header_lines_iterator(headers_, idx_); 634 } 635 636 self& operator++() { 637 reverse_iterator_base::increment(); 638 return *this; 639 } 640 641 self& operator--() { 642 reverse_iterator_base::decrement(); 643 return *this; 644 } 645 protected: 646 const_reverse_header_lines_iterator(const BalsaHeaders* headers, 647 HeaderLines::size_type index) : 648 reverse_iterator_base(headers, index) {} 649 650 friend class BalsaHeaders; 651 }; 652 653 // An iterator that only stops at lines with a particular key. 654 // See also GetIteratorForKey. 655 // 656 // Check against header_lines_key_end() to determine when iteration is 657 // finished. header_lines_end() will also work. 658 class const_header_lines_key_iterator : public iterator_base { 659 friend class BalsaHeaders; 660 public: 661 typedef const_header_lines_key_iterator self; 662 663 self& operator++() { 664 do { 665 iterator_base::increment(); 666 } while (!AtEnd() && 667 !StringPieceUtils::EqualIgnoreCase(key_, (**this).first)); 668 return *this; 669 } 670 671 void operator++(int ignore) { 672 ++(*this); 673 } 674 675 // Only forward-iteration makes sense, so no operator-- defined. 676 677 private: 678 const_header_lines_key_iterator(const BalsaHeaders* headers, 679 HeaderLines::size_type index, 680 const base::StringPiece& key) 681 : iterator_base(headers, index), 682 key_(key) { 683 } 684 685 // Should only be used for creating an end iterator. 686 const_header_lines_key_iterator(const BalsaHeaders* headers, 687 HeaderLines::size_type index) 688 : iterator_base(headers, index) { 689 } 690 691 bool AtEnd() const { 692 return *this >= headers_->header_lines_end(); 693 } 694 695 base::StringPiece key_; 696 }; 697 698 // TODO(fenix): Revisit the amount of bytes initially allocated to the second 699 // block of the balsa_buffer_. It may make sense to pre-allocate some amount 700 // (roughly the amount we'd append in new headers such as X-User-Ip, etc.) 701 BalsaHeaders() : 702 balsa_buffer_(4096), 703 content_length_(0), 704 content_length_status_(BalsaHeadersEnums::NO_CONTENT_LENGTH), 705 parsed_response_code_(0), 706 firstline_buffer_base_idx_(0), 707 whitespace_1_idx_(0), 708 non_whitespace_1_idx_(0), 709 whitespace_2_idx_(0), 710 non_whitespace_2_idx_(0), 711 whitespace_3_idx_(0), 712 non_whitespace_3_idx_(0), 713 whitespace_4_idx_(0), 714 end_of_firstline_idx_(0), 715 transfer_encoding_is_chunked_(false) { } 716 717 const_header_lines_iterator header_lines_begin() { 718 return HeaderLinesBeginHelper<const_header_lines_iterator>(); 719 } 720 721 const_header_lines_iterator header_lines_begin() const { 722 return HeaderLinesBeginHelper<const_header_lines_iterator>(); 723 } 724 725 const_header_lines_iterator header_lines_end() { 726 return HeaderLinesEndHelper<const_header_lines_iterator>(); 727 } 728 729 const_header_lines_iterator header_lines_end() const { 730 return HeaderLinesEndHelper<const_header_lines_iterator>(); 731 } 732 733 const_reverse_header_lines_iterator header_lines_rbegin() { 734 return const_reverse_header_lines_iterator(header_lines_end()); 735 } 736 737 const_reverse_header_lines_iterator header_lines_rbegin() const { 738 return const_reverse_header_lines_iterator(header_lines_end()); 739 } 740 741 const_reverse_header_lines_iterator header_lines_rend() { 742 return const_reverse_header_lines_iterator(header_lines_begin()); 743 } 744 745 const_reverse_header_lines_iterator header_lines_rend() const { 746 return const_reverse_header_lines_iterator(header_lines_begin()); 747 } 748 749 const_header_lines_key_iterator header_lines_key_end() const { 750 return HeaderLinesEndHelper<const_header_lines_key_iterator>(); 751 } 752 753 void erase(const const_header_lines_iterator& it) { 754 DCHECK_EQ(it.headers_, this); 755 DCHECK_LT(it.idx_, header_lines_.size()); 756 DCHECK_GE(it.idx_, 0u); 757 header_lines_[it.idx_].skip = true; 758 } 759 760 void Clear(); 761 762 void Swap(BalsaHeaders* other); 763 764 void CopyFrom(const BalsaHeaders& other); 765 766 void HackHeader(const base::StringPiece& key, const base::StringPiece& value); 767 768 // Same as AppendToHeader, except that it will attempt to preserve 769 // header ordering. 770 // Note that this will always append to an existing header, if available, 771 // without moving the header around, or collapsing multiple header lines 772 // with the same key together. For this reason, it only 'attempts' to 773 // preserve header ordering. 774 // TODO(fenix): remove this function and rename all occurances 775 // of it in the code to AppendToHeader when the condition above 776 // has been satisified. 777 void HackAppendToHeader(const base::StringPiece& key, 778 const base::StringPiece& value); 779 780 // Replaces header entries with key 'key' if they exist, or appends 781 // a new header if none exist. See 'AppendHeader' below for additional 782 // comments about ContentLength and TransferEncoding headers. Note that this 783 // will allocate new storage every time that it is called. 784 // TODO(fenix): modify this function to reuse existing storage 785 // if it is available. 786 void ReplaceOrAppendHeader(const base::StringPiece& key, 787 const base::StringPiece& value); 788 789 // Append a new header entry to the header object. Clients who wish to append 790 // Content-Length header should use SetContentLength() method instead of 791 // adding the content length header using AppendHeader (manually adding the 792 // content length header will not update the content_length_ and 793 // content_length_status_ values). 794 // Similarly, clients who wish to add or remove the transfer encoding header 795 // in order to apply or remove chunked encoding should use SetChunkEncoding() 796 // instead. 797 void AppendHeader(const base::StringPiece& key, 798 const base::StringPiece& value); 799 800 // Appends ',value' to an existing header named 'key'. If no header with the 801 // correct key exists, it will call AppendHeader(key, value). Calling this 802 // function on a key which exists several times in the headers will produce 803 // unpredictable results. 804 void AppendToHeader(const base::StringPiece& key, 805 const base::StringPiece& value); 806 807 // Prepends 'value,' to an existing header named 'key'. If no header with the 808 // correct key exists, it will call AppendHeader(key, value). Calling this 809 // function on a key which exists several times in the headers will produce 810 // unpredictable results. 811 void PrependToHeader(const base::StringPiece& key, 812 const base::StringPiece& value); 813 814 const base::StringPiece GetHeader(const base::StringPiece& key) const; 815 816 // Iterates over all currently valid header lines, appending their 817 // values into the vector 'out', in top-to-bottom order. 818 // Header-lines which have been erased are not currently valid, and 819 // will not have their values appended. Empty values will be 820 // represented as empty string. If 'key' doesn't exist in the headers at 821 // all, out will not be changed. We do not clear the vector out 822 // before adding new entries. If there are header lines with matching 823 // key but empty value then they are also added to the vector out. 824 // (Basically empty values are not treated in any special manner). 825 // 826 // Example: 827 // Input header: 828 // "GET / HTTP/1.0\r\n" 829 // "key1: v1\r\n" 830 // "key1: \r\n" 831 // "key1:\r\n" 832 // "key1: v1\r\n" 833 // "key1:v2\r\n" 834 // 835 // vector out is initially: ["foo"] 836 // vector out after GetAllOfHeader("key1", &out) is: 837 // ["foo", "v1", "", "", "v2", "v1", "v2"] 838 839 void GetAllOfHeader(const base::StringPiece& key, 840 std::vector<base::StringPiece>* out) const; 841 842 // Joins all values for key into a comma-separated string in out. 843 // More efficient than calling JoinStrings on result of GetAllOfHeader if 844 // you don't need the intermediate vector<StringPiece>. 845 void GetAllOfHeaderAsString(const base::StringPiece& key, 846 std::string* out) const; 847 848 // Returns true if RFC 2616 Section 14 indicates that header can 849 // have multiple values. 850 static bool IsMultivaluedHeader(const base::StringPiece& header); 851 852 // Determine if a given header is present. 853 inline bool HasHeader(const base::StringPiece& key) const { 854 return (GetConstHeaderLinesIterator(key, header_lines_.begin()) != 855 header_lines_.end()); 856 } 857 858 // Returns true iff any header 'key' exists with non-empty value. 859 bool HasNonEmptyHeader(const base::StringPiece& key) const; 860 861 const_header_lines_iterator GetHeaderPosition( 862 const base::StringPiece& key) const; 863 864 // Returns a forward-only iterator that only stops at lines matching key. 865 // String backing 'key' must remain valid for lifetime of iterator. 866 // 867 // Check returned iterator against header_lines_key_end() to determine when 868 // iteration is finished. 869 const_header_lines_key_iterator GetIteratorForKey( 870 const base::StringPiece& key) const; 871 872 void RemoveAllOfHeader(const base::StringPiece& key); 873 874 // Removes all headers starting with 'key' [case insensitive] 875 void RemoveAllHeadersWithPrefix(const base::StringPiece& key); 876 877 // Returns the lower bound of memory used by this header object, including 878 // all internal buffers and data structure. Some of the memory used cannot be 879 // directly measure. For example, memory used for bookkeeping by standard 880 // containers. 881 size_t GetMemoryUsedLowerBound() const; 882 883 // Returns the upper bound on the required buffer space to fully write out 884 // the header object (this include the first line, all header lines, and the 885 // final CRLF that marks the ending of the header). 886 size_t GetSizeForWriteBuffer() const; 887 888 // The following WriteHeader* methods are template member functions that 889 // place one requirement on the Buffer class: it must implement a Write 890 // method that takes a pointer and a length. The buffer passed in is not 891 // required to be stretchable. For non-stretchable buffers, the user must 892 // call GetSizeForWriteBuffer() to find out the upper bound on the output 893 // buffer space required to make sure that the entire header is serialized. 894 // BalsaHeaders will not check that there is adequate space in the buffer 895 // object during the write. 896 897 // Writes the entire header and the final CRLF that marks the end of the HTTP 898 // header section to the buffer. After this method returns, no more header 899 // data should be written to the buffer. 900 template <typename Buffer> 901 void WriteHeaderAndEndingToBuffer(Buffer* buffer) const { 902 WriteToBuffer(buffer); 903 WriteHeaderEndingToBuffer(buffer); 904 } 905 906 // Writes the final CRLF to the buffer to terminate the HTTP header section. 907 // After this method returns, no more header data should be written to the 908 // buffer. 909 template <typename Buffer> 910 static void WriteHeaderEndingToBuffer(Buffer* buffer) { 911 buffer->Write("\r\n", 2); 912 } 913 914 // Writes the entire header to the buffer without the CRLF that terminates 915 // the HTTP header. This lets users append additional header lines using 916 // WriteHeaderLineToBuffer and then terminate the header with 917 // WriteHeaderEndingToBuffer as the header is serialized to the 918 // buffer, without having to first copy the header. 919 template <typename Buffer> 920 void WriteToBuffer(Buffer* buffer) const { 921 // write the first line. 922 const size_t firstline_len = whitespace_4_idx_ - non_whitespace_1_idx_; 923 const char* stream_begin = GetPtr(firstline_buffer_base_idx_); 924 buffer->Write(stream_begin + non_whitespace_1_idx_, firstline_len); 925 buffer->Write("\r\n", 2); 926 const HeaderLines::size_type end = header_lines_.size(); 927 for (HeaderLines::size_type i = 0; i < end; ++i) { 928 const HeaderLineDescription& line = header_lines_[i]; 929 if (line.skip) { 930 continue; 931 } 932 const char* line_ptr = GetPtr(line.buffer_base_idx); 933 WriteHeaderLineToBuffer( 934 buffer, 935 base::StringPiece(line_ptr + line.first_char_idx, 936 line.key_end_idx - line.first_char_idx), 937 base::StringPiece(line_ptr + line.value_begin_idx, 938 line.last_char_idx - line.value_begin_idx)); 939 } 940 } 941 942 // Takes a header line in the form of a key/value pair and append it to the 943 // buffer. This function should be called after WriteToBuffer to 944 // append additional header lines to the header without copying the header. 945 // When the user is done with appending to the buffer, 946 // WriteHeaderEndingToBuffer must be used to terminate the HTTP 947 // header in the buffer. This method is a no-op if key is empty. 948 template <typename Buffer> 949 static void WriteHeaderLineToBuffer(Buffer* buffer, 950 const base::StringPiece& key, 951 const base::StringPiece& value) { 952 // if the key is empty, we don't want to write the rest because it 953 // will not be a well-formed header line. 954 if (key.size() > 0) { 955 buffer->Write(key.data(), key.size()); 956 buffer->Write(": ", 2); 957 buffer->Write(value.data(), value.size()); 958 buffer->Write("\r\n", 2); 959 } 960 } 961 962 // Dump the textural representation of the header object to a string, which 963 // is suitable for writing out to logs. All CRLF will be printed out as \n. 964 // This function can be called on a header object in any state. Raw header 965 // data will be printed out if the header object is not completely parsed, 966 // e.g., when there was an error in the middle of parsing. 967 // The header content is appended to the string; the original content is not 968 // cleared. 969 void DumpToString(std::string* str) const; 970 971 const base::StringPiece first_line() const { 972 DCHECK_GE(whitespace_4_idx_, non_whitespace_1_idx_); 973 return base::StringPiece(BeginningOfFirstLine() + non_whitespace_1_idx_, 974 whitespace_4_idx_ - non_whitespace_1_idx_); 975 } 976 977 // Returns the parsed value of the response code if it has been parsed. 978 // Guaranteed to return 0 when unparsed (though it is a much better idea to 979 // verify that the BalsaFrame had no errors while parsing). 980 // This may return response codes which are outside the normal bounds of 981 // HTTP response codes-- it is up to the user of this class to ensure that 982 // the response code is one which is interpretable. 983 size_t parsed_response_code() const { return parsed_response_code_; } 984 985 const base::StringPiece request_method() const { 986 DCHECK_GE(whitespace_2_idx_, non_whitespace_1_idx_); 987 return base::StringPiece(BeginningOfFirstLine() + non_whitespace_1_idx_, 988 whitespace_2_idx_ - non_whitespace_1_idx_); 989 } 990 991 const base::StringPiece response_version() const { 992 // Note: There is no difference between request_method() and 993 // response_version(). They both could be called 994 // GetFirstTokenFromFirstline()... but that wouldn't be anywhere near as 995 // descriptive. 996 return request_method(); 997 } 998 999 const base::StringPiece request_uri() const { 1000 DCHECK_GE(whitespace_3_idx_, non_whitespace_2_idx_); 1001 return base::StringPiece(BeginningOfFirstLine() + non_whitespace_2_idx_, 1002 whitespace_3_idx_ - non_whitespace_2_idx_); 1003 } 1004 1005 const base::StringPiece response_code() const { 1006 // Note: There is no difference between request_uri() and response_code(). 1007 // They both could be called GetSecondtTokenFromFirstline(), but, as noted 1008 // in an earlier comment, that wouldn't be as descriptive. 1009 return request_uri(); 1010 } 1011 1012 const base::StringPiece request_version() const { 1013 DCHECK_GE(whitespace_4_idx_, non_whitespace_3_idx_); 1014 return base::StringPiece(BeginningOfFirstLine() + non_whitespace_3_idx_, 1015 whitespace_4_idx_ - non_whitespace_3_idx_); 1016 } 1017 1018 const base::StringPiece response_reason_phrase() const { 1019 // Note: There is no difference between request_version() and 1020 // response_reason_phrase(). They both could be called 1021 // GetThirdTokenFromFirstline(), but, as noted in an earlier comment, that 1022 // wouldn't be as descriptive. 1023 return request_version(); 1024 } 1025 1026 // Note that SetFirstLine will not update the internal indices for the 1027 // various bits of the first-line (and may set them all to zero). 1028 // If you'd like to use the accessors for the various bits of the firstline, 1029 // then you should use the Set* functions, or SetFirstlineFromStringPieces, 1030 // below, instead. 1031 // 1032 void SetFirstlineFromStringPieces(const base::StringPiece& firstline_a, 1033 const base::StringPiece& firstline_b, 1034 const base::StringPiece& firstline_c); 1035 1036 void SetRequestFirstlineFromStringPieces(const base::StringPiece& method, 1037 const base::StringPiece& uri, 1038 const base::StringPiece& version) { 1039 SetFirstlineFromStringPieces(method, uri, version); 1040 } 1041 1042 void SetResponseFirstlineFromStringPieces( 1043 const base::StringPiece& version, 1044 const base::StringPiece& code, 1045 const base::StringPiece& reason_phrase) { 1046 SetFirstlineFromStringPieces(version, code, reason_phrase); 1047 } 1048 1049 // These functions are exactly the same, except that their names are 1050 // different. This is done so that the code using this class is more 1051 // expressive. 1052 void SetRequestMethod(const base::StringPiece& method); 1053 void SetResponseVersion(const base::StringPiece& version); 1054 1055 void SetRequestUri(const base::StringPiece& uri); 1056 void SetResponseCode(const base::StringPiece& code); 1057 void set_parsed_response_code(size_t parsed_response_code) { 1058 parsed_response_code_ = parsed_response_code; 1059 } 1060 void SetParsedResponseCodeAndUpdateFirstline(size_t parsed_response_code); 1061 1062 // These functions are exactly the same, except that their names are 1063 // different. This is done so that the code using this class is more 1064 // expressive. 1065 void SetRequestVersion(const base::StringPiece& version); 1066 void SetResponseReasonPhrase(const base::StringPiece& reason_phrase); 1067 1068 // The biggest problem with SetFirstLine is that we don't want to use a 1069 // separate buffer for it. The second biggest problem with it is that the 1070 // first biggest problem requires that we store offsets into a buffer instead 1071 // of pointers into a buffer. Cuteness aside, SetFirstLine doesn't parse 1072 // the individual fields of the firstline, and so accessors to those fields 1073 // will not work properly after calling SetFirstLine. If you want those 1074 // accessors to work, use the Set* functions above this one. 1075 // SetFirstLine is stuff useful, however, if all you care about is correct 1076 // serialization with the rest of the header object. 1077 void SetFirstLine(const base::StringPiece& line); 1078 1079 // Simple accessors to some of the internal state 1080 bool transfer_encoding_is_chunked() const { 1081 return transfer_encoding_is_chunked_; 1082 } 1083 1084 static bool ResponseCodeImpliesNoBody(int code) { 1085 // From HTTP spec section 6.1.1 all 1xx responses must not have a body, 1086 // as well as 204 No Content and 304 Not Modified. 1087 return ((code >= 100) && (code <= 199)) || (code == 204) || (code == 304); 1088 } 1089 1090 // Note: never check this for requests. Nothing bad will happen if you do, 1091 // but spec does not allow requests framed by connection close. 1092 // TODO(vitaliyl): refactor. 1093 bool is_framed_by_connection_close() const { 1094 // We declare that response is framed by connection close if it has no 1095 // content-length, no transfer encoding, and is allowed to have a body by 1096 // the HTTP spec. 1097 // parsed_response_code_ is 0 for requests, so ResponseCodeImpliesNoBody 1098 // will return false. 1099 return (content_length_status_ == BalsaHeadersEnums::NO_CONTENT_LENGTH) && 1100 !transfer_encoding_is_chunked_ && 1101 !ResponseCodeImpliesNoBody(parsed_response_code_); 1102 } 1103 1104 size_t content_length() const { return content_length_; } 1105 BalsaHeadersEnums::ContentLengthStatus content_length_status() const { 1106 return content_length_status_; 1107 } 1108 1109 // SetContentLength and SetChunkEncoding modifies the header object to use 1110 // content-length and transfer-encoding headers in a consistent manner. They 1111 // set all internal flags and status so client can get a consistent view from 1112 // various accessors. 1113 void SetContentLength(size_t length); 1114 void SetChunkEncoding(bool chunk_encode); 1115 1116 protected: 1117 friend class BalsaFrame; 1118 friend class SpdyFrame; 1119 friend class HTTPMessage; 1120 friend class BalsaHeadersTokenUtils; 1121 1122 const char* BeginningOfFirstLine() const { 1123 return GetPtr(firstline_buffer_base_idx_); 1124 } 1125 1126 char* GetPtr(BalsaBuffer::Blocks::size_type block_idx) { 1127 return balsa_buffer_.GetPtr(block_idx); 1128 } 1129 1130 const char* GetPtr(BalsaBuffer::Blocks::size_type block_idx) const { 1131 return balsa_buffer_.GetPtr(block_idx); 1132 } 1133 1134 void WriteFromFramer(const char* ptr, size_t size) { 1135 balsa_buffer_.WriteToContiguousBuffer(base::StringPiece(ptr, size)); 1136 } 1137 1138 void DoneWritingFromFramer() { 1139 balsa_buffer_.NoMoreWriteToContiguousBuffer(); 1140 } 1141 1142 const char* OriginalHeaderStreamBegin() const { 1143 return balsa_buffer_.StartOfFirstBlock(); 1144 } 1145 1146 const char* OriginalHeaderStreamEnd() const { 1147 return balsa_buffer_.EndOfFirstBlock(); 1148 } 1149 1150 size_t GetReadableBytesFromHeaderStream() const { 1151 return OriginalHeaderStreamEnd() - OriginalHeaderStreamBegin(); 1152 } 1153 1154 void GetReadablePtrFromHeaderStream(const char** p, size_t* s) { 1155 *p = OriginalHeaderStreamBegin(); 1156 *s = GetReadableBytesFromHeaderStream(); 1157 } 1158 1159 base::StringPiece GetValueFromHeaderLineDescription( 1160 const HeaderLineDescription& line) const; 1161 1162 void AddAndMakeDescription(const base::StringPiece& key, 1163 const base::StringPiece& value, 1164 HeaderLineDescription* d); 1165 1166 void AppendOrPrependAndMakeDescription(const base::StringPiece& key, 1167 const base::StringPiece& value, 1168 bool append, 1169 HeaderLineDescription* d); 1170 1171 // Removes all header lines with the given key starting at start. 1172 void RemoveAllOfHeaderStartingAt(const base::StringPiece& key, 1173 HeaderLines::iterator start); 1174 1175 // If the 'key' does not exist in the headers, calls 1176 // AppendHeader(key, value). Otherwise if append is true, appends ',value' 1177 // to the first existing header with key 'key'. If append is false, prepends 1178 // 'value,' to the first existing header with key 'key'. 1179 void AppendOrPrependToHeader(const base::StringPiece& key, 1180 const base::StringPiece& value, 1181 bool append); 1182 1183 HeaderLines::const_iterator GetConstHeaderLinesIterator( 1184 const base::StringPiece& key, 1185 HeaderLines::const_iterator start) const; 1186 1187 HeaderLines::iterator GetHeaderLinesIteratorNoSkip( 1188 const base::StringPiece& key, 1189 HeaderLines::iterator start); 1190 1191 HeaderLines::iterator GetHeaderLinesIterator( 1192 const base::StringPiece& key, 1193 HeaderLines::iterator start); 1194 1195 template <typename IteratorType> 1196 const IteratorType HeaderLinesBeginHelper() const { 1197 if (header_lines_.empty()) { 1198 return IteratorType(this, 0); 1199 } 1200 const HeaderLines::size_type header_lines_size = header_lines_.size(); 1201 for (HeaderLines::size_type i = 0; i < header_lines_size; ++i) { 1202 if (header_lines_[i].skip == false) { 1203 return IteratorType(this, i); 1204 } 1205 } 1206 return IteratorType(this, 0); 1207 } 1208 1209 template <typename IteratorType> 1210 const IteratorType HeaderLinesEndHelper() const { 1211 if (header_lines_.empty()) { 1212 return IteratorType(this, 0); 1213 } 1214 const HeaderLines::size_type header_lines_size = header_lines_.size(); 1215 HeaderLines::size_type i = header_lines_size; 1216 do { 1217 --i; 1218 if (header_lines_[i].skip == false) { 1219 return IteratorType(this, i + 1); 1220 } 1221 } while (i != 0); 1222 return IteratorType(this, 0); 1223 } 1224 1225 // At the moment, this function will always return the original headers. 1226 // In the future, it may not do so after erasing header lines, modifying 1227 // header lines, or modifying the first line. 1228 // For this reason, it is strongly suggested that use of this function is 1229 // only acceptable for the purpose of debugging parse errors seen by the 1230 // BalsaFrame class. 1231 base::StringPiece OriginalHeadersForDebugging() const { 1232 return base::StringPiece(OriginalHeaderStreamBegin(), 1233 OriginalHeaderStreamEnd() - OriginalHeaderStreamBegin()); 1234 } 1235 1236 BalsaBuffer balsa_buffer_; 1237 1238 size_t content_length_; 1239 BalsaHeadersEnums::ContentLengthStatus content_length_status_; 1240 size_t parsed_response_code_; 1241 // HTTP firstlines all have the following structure: 1242 // LWS NONWS LWS NONWS LWS NONWS NOTCRLF CRLF 1243 // [\t \r\n]+ [^\t ]+ [\t ]+ [^\t ]+ [\t ]+ [^\t ]+ [^\r\n]+ "\r\n" 1244 // ws1 nws1 ws2 nws2 ws3 nws3 ws4 1245 // | [-------) [-------) [----------------) 1246 // REQ: method request_uri version 1247 // RESP: version statuscode reason 1248 // 1249 // The first NONWS->LWS component we'll call firstline_a. 1250 // The second firstline_b, and the third firstline_c. 1251 // 1252 // firstline_a goes from nws1 to (but not including) ws2 1253 // firstline_b goes from nws2 to (but not including) ws3 1254 // firstline_c goes from nws3 to (but not including) ws4 1255 // 1256 // In the code: 1257 // ws1 == whitespace_1_idx_ 1258 // nws1 == non_whitespace_1_idx_ 1259 // ws2 == whitespace_2_idx_ 1260 // nws2 == non_whitespace_2_idx_ 1261 // ws3 == whitespace_3_idx_ 1262 // nws3 == non_whitespace_3_idx_ 1263 // ws4 == whitespace_4_idx_ 1264 BalsaBuffer::Blocks::size_type firstline_buffer_base_idx_; 1265 size_t whitespace_1_idx_; 1266 size_t non_whitespace_1_idx_; 1267 size_t whitespace_2_idx_; 1268 size_t non_whitespace_2_idx_; 1269 size_t whitespace_3_idx_; 1270 size_t non_whitespace_3_idx_; 1271 size_t whitespace_4_idx_; 1272 size_t end_of_firstline_idx_; 1273 1274 bool transfer_encoding_is_chunked_; 1275 1276 HeaderLines header_lines_; 1277}; 1278 1279} // namespace net 1280 1281#endif // NET_TOOLS_FLIP_SERVER_BALSA_HEADERS_H_ 1282 1283