Exemplo n.º 1
0
uint32_t HPACKDecoder::decodeIndexedHeader(HPACKDecodeBuffer& dbuf,
                                           headers_t* emitted) {
  uint32_t index;
  err_ = dbuf.decodeInteger(7, index);
  if (err_ != HPACK::DecodeError::NONE) {
    LOG(ERROR) << "Decode error decoding index err_=" << err_;
    return 0;
  }
  // validate the index
  if (index == 0 || !isValid(index)) {
    LOG(ERROR) << "received invalid index: " << index;
    err_ = HPACK::DecodeError::INVALID_INDEX;
    return 0;
  }
  uint32_t emittedSize = 0;

  if (isStatic(index)) {
    auto& header = getStaticHeader(index);
    emittedSize = emit(header, emitted);
  } else {
    auto& header = getDynamicHeader(index);
    emittedSize = emit(header, emitted);
  }
  return emittedSize;
}
Exemplo n.º 2
0
void HPACKEncoder::encodeHeader(const HPACKHeader& header) {
  uint32_t index = getIndex(header);
  if (index) {
    // firstly check if it's part of the static table
    if (isStatic(index)) {
      encodeAsIndex(index);
      // insert the static header in the dynamic header table
      // to take advantage of the delta compression
      if (table_.add(getStaticHeader(index))) {
        table_.addReference(1);
      }
    } else if (!table_.inReferenceSet(globalToDynamicIndex(index))) {
      table_.addReference(globalToDynamicIndex(index));
      encodeAsIndex(index);
    } else {
      // there's nothing to encode, but keep a record for it in case of eviction
      table_.addSkippedReference(globalToDynamicIndex(index));
    }
  } else {
    encodeAsLiteral(header);
  }
}
Exemplo n.º 3
0
uint32_t HPACKDecoder::decodeIndexedHeader(HPACKDecodeBuffer& dbuf,
                                           headers_t* emitted) {
  uint32_t index;
  err_ = dbuf.decodeInteger(7, index);
  if (err_ != DecodeError::NONE) {
    LOG(ERROR) << "Decode error decoding header index err_=" << err_;
    return 0;
  }
  if (index == 0) {
    table_.clearReferenceSet();
    return 0;
  }
  // validate the index
  if (!isValid(index)) {
    LOG(ERROR) << "received invalid index: " << index;
    err_ = DecodeError::INVALID_INDEX;
    return 0;
  }
  uint32_t emittedSize = 0;
  // a static index cannot be part of the reference set
  if (isStatic(index)) {
    auto& header = getStaticHeader(index);
    emittedSize = emit(header, emitted);
    if (table_.add(header)) {
      table_.addReference(1);
    }
  } else if (table_.inReferenceSet(globalToDynamicIndex(index))) {
    // index remove operation
    table_.removeReference(globalToDynamicIndex(index));
  } else {
    auto& header = getDynamicHeader(index);
    emittedSize = emit(header, emitted);
    table_.addReference(globalToDynamicIndex(index));
  }
  return emittedSize;
}
Exemplo n.º 4
0
std::string EditFoodResponse::getHeader()
{
    return getStaticHeader();
}
std::string DeleteInventoryResponse::getHeader()
{
    return getStaticHeader();
}