tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

nsHttpChunkedDecoder.h (1570B)


      1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
      2 /* This Source Code Form is subject to the terms of the Mozilla Public
      3 * License, v. 2.0. If a copy of the MPL was not distributed with this
      4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      5 
      6 #ifndef nsHttpChunkedDecoder_h__
      7 #define nsHttpChunkedDecoder_h__
      8 
      9 #include "nsError.h"
     10 #include "nsString.h"
     11 #include "nsHttpHeaderArray.h"
     12 
     13 namespace mozilla {
     14 namespace net {
     15 
     16 class nsHttpChunkedDecoder {
     17 public:
     18  nsHttpChunkedDecoder() = default;
     19  ~nsHttpChunkedDecoder() = default;
     20 
     21  bool ReachedEOF() { return mReachedEOF; }
     22 
     23  // called by the transaction to handle chunked content.
     24  [[nodiscard]] nsresult HandleChunkedContent(char* buf, uint32_t count,
     25                                              uint32_t* contentRead,
     26                                              uint32_t* contentRemaining);
     27 
     28  nsHttpHeaderArray* Trailers() { return mTrailers.get(); }
     29 
     30  UniquePtr<nsHttpHeaderArray> TakeTrailers() { return std::move(mTrailers); }
     31 
     32  // How mush data is still missing(needs to arrive) from the current chunk.
     33  uint32_t GetChunkRemaining() { return mChunkRemaining; }
     34 
     35 private:
     36  [[nodiscard]] nsresult ParseChunkRemaining(char* buf, uint32_t count,
     37                                             uint32_t* bytesConsumed);
     38 
     39 private:
     40  UniquePtr<nsHttpHeaderArray> mTrailers;
     41  uint32_t mChunkRemaining{0};
     42  nsCString mLineBuf;  // may hold a partial line
     43  bool mReachedEOF{false};
     44  bool mWaitEOF{false};
     45 };
     46 
     47 }  // namespace net
     48 }  // namespace mozilla
     49 
     50 #endif