Skip to content

Commit

Permalink
Create README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
kelbon committed Oct 17, 2024
1 parent 6ff641c commit fa13197
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 2 deletions.
60 changes: 60 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@

Complete implementation of HPACK (Header Compression for HTTP/2, fully compliant RFC 7541)

encode:

```cpp
#include <hpack/encoder.hpp>

void encode_my_headers(hpack::encoder& enc, std::vector<hpack::bytes>& bytes;) {
// memory effective by default
enc.encode("name", "value", std::back_inserter(bytes));
// or by hands
enc.encode_header_fully_indexed(hpack::static_table_t::status_200, std::back_inserter(bytes));
}

```
decode
```cpp
#include <hpack/decoder.hpp>
void decode_my_headers(hpack::decoder& d, std::span<const hpack::byte_t> bytes) {
hpack::decode_headers_block(e, bytes, [&](std::string_view name, std::string_view value) {
// use name/value somehow
});
}
```

adding with cmake:

Preferred way with [CPM](https://github.com/cpm-cmake/CPM.cmake)

```cmake
CPMAddPackage(
NAME HPACK
GIT_REPOSITORY https://github.com/kelbon/HPACK
GIT_TAG origin/master
)
target_link_libraries(MyTargetName hpacklib)
```

simple way with fetch content:

```cmake
include(FetchContent)
FetchContent_Declare(
HPACK
GIT_REPOSITORY https://github.com/kelbon/HPACK
GIT_TAG origin/master
)
FetchContent_MakeAvailable(HPACK)
target_link_libraries(MyTargetName hpacklib)
```
3 changes: 2 additions & 1 deletion include/hpack/decoder.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ struct header_view {

// header may be not present if default contructed or table_size_update happen instead of header
explicit operator bool() const noexcept {
return name || value;
return !!name;
}

header_view& operator=(header_view&&) = default;
Expand Down Expand Up @@ -142,6 +142,7 @@ struct decoder {
void decode_header(In& in, In e, header_view& out);

// returns status code
// its always first header of response, so 'in' must point to first byte of headers block
int decode_response_status(In& in, In e);
};

Expand Down
1 change: 0 additions & 1 deletion src/decoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,6 @@ void decoder::decode_header(In& in, In e, header_view& out) {
handle_protocol_error();
}

// returns status code
int decoder::decode_response_status(In& in, In e) {
if (*in & 0b1000'0000) {
// fast path, fully indexed
Expand Down

0 comments on commit fa13197

Please sign in to comment.