Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changes to be committed: #10

Merged
merged 2 commits into from
Sep 28, 2024
Merged

Changes to be committed: #10

merged 2 commits into from
Sep 28, 2024

Conversation

khulnasoft-bot
Copy link
Contributor

@khulnasoft-bot khulnasoft-bot commented Sep 27, 2024

User description

Notes for Reviewers

This PR fixes #

Signed commits

  • [*] Yes, I signed my commits.

PR Type

enhancement, documentation, formatting, configuration changes, dependencies, bug fix, tests, miscellaneous


Description

  • Introduced a new gRPC-web bridging module and added tests for its functionality.
  • Enhanced the memory cache to support multiple concurrent writers and streaming write tags.
  • Improved import order across multiple modules for better readability.
  • Updated documentation with improved formatting and added new sections, including a RateLimiter quickstart guide.
  • Updated Rust toolchain version and added a new Semgrep analysis workflow in GitHub actions.
  • Corrected the company name in copyright notices across various files.
  • Added a new configuration file for bongonet tests and updated existing configurations.
  • Updated authorship information and added dependencies in Cargo.toml files.
  • Fixed a bug in the gateway example by correcting a metric name.

Changes walkthrough 📝

Relevant files
Enhancement
19 files
server.rs
Update copyright and test cases for new domain.                   

bongonet-core/src/protocols/http/v1/server.rs

  • Corrected the company name in the copyright notice.
  • Updated test cases to use the new host domain bongonet.khulnasoft.com.
  • Reorganized imports for better readability.
  • +39/-31 
    grpc_web.rs
    Add gRPC-web bridging module with tests.                                 

    bongonet-core/src/protocols/http/bridge/grpc_web.rs

  • Introduced a new module for bridging gRPC to gRPC-web.
  • Implemented functions to filter request and response headers.
  • Added tests for the new gRPC-web functionality.
  • +341/-0 
    memory.rs
    Support concurrent writers and streaming write tags in memory cache.

    bongonet-cache/src/memory.rs

  • Added support for multiple concurrent writers in memory cache.
  • Introduced AtomicU64 for managing temporary object IDs.
  • Implemented streaming write tag functionality.
  • +79/-19 
    storage.rs
    Enhance Storage trait with streaming write tag support.   

    bongonet-cache/src/storage.rs

  • Added streaming write tag support to the Storage trait.
  • Introduced U64WriteId and U32WriteId for streaming write
    identification.
  • +103/-2 
    raw_connect.rs
    Update test cases for new domain and improve import order.

    bongonet-core/src/protocols/raw_connect.rs

  • Updated test cases to use the new host domain bongonet.khulnasoft.com.
  • Reorganized imports for better readability.
  • +15/-12 
    lib.rs
    Improve cache lock tracing and handling of cache misses. 

    bongonet-cache/src/lib.rs

  • Added a tag to cache lock spans for better tracing.
  • Ensured cache meta is not set for cache misses.
  • +21/-4   
    lock.rs
    Enhance lock handling with better error logging.                 

    bongonet-cache/src/lock.rs

  • Added logging for semaphore acquisition errors.
  • Improved handling of lock expiration and timeout.
  • +21/-8   
    lib.rs
    Support END_STREAM flag in HTTP/2 requests.                           

    bongonet-http/src/lib.rs

  • Added support for setting and checking END_STREAM flag in HTTP/2
    requests.
  • Updated RequestHeader to include send_end_stream functionality.
  • +39/-1   
    grpc_web.rs
    Introduce gRPC-web bridge module for HTTP.                             

    bongonet-core/src/modules/http/grpc_web.rs

  • Added a new module for gRPC-web bridging.
  • Implemented request and response header filtering for gRPC-web.
  • +80/-0   
    proxy_h2.rs
    Support END_STREAM flag in HTTP/2 proxy headers.                 

    bongonet-proxy/src/proxy_h2.rs

  • Added support for END_STREAM flag in HTTP/2 headers.
  • Improved handling of empty data frames.
  • +14/-13 
    mod.rs
    Add gRPC-web module and response trailer filtering.           

    bongonet-core/src/modules/http/mod.rs

  • Added grpc_web module to HTTP modules.
  • Implemented response trailer filtering.
  • +33/-3   
    lib.rs
    Handle response trailers and improve error handling.         

    bongonet-proxy/src/lib.rs

  • Added response trailer handling in HTTP tasks.
  • Improved error handling by releasing cache lock on error.
  • +18/-3   
    server.rs
    Update test cases for new domain in TLS server.                   

    bongonet-core/src/protocols/tls/boringssl_openssl/server.rs

  • Updated test cases to use the new host domain bongonet.khulnasoft.com.

  • +4/-4     
    rate.rs
    Add configurable estimator settings for Rate.                       

    bongonet-limits/src/rate.rs

  • Added a new constructor for Rate with configurable estimator settings.

  • +13/-3   
    mod.rs
    Add bridge module and update server name.                               

    bongonet-core/src/protocols/http/mod.rs

  • Added bridge module to HTTP protocols.
  • Updated server name constant.
  • +3/-2     
    cache_control.rs
    Enhance directive value parsing in cache control.               

    bongonet-cache/src/cache_control.rs

    • Improved parsing of directive values by using array references.
    +3/-3     
    server_utils.rs
    Add cache hit filter for force expiry control.                     

    bongonet-proxy/tests/utils/server_utils.rs

    • Added cache hit filter to control force expiry via headers.
    +14/-1   
    max_file_size.rs
    Support streaming write tags in max file size handler.     

    bongonet-cache/src/max_file_size.rs

    • Added streaming write tag support to max file size miss handler.
    +5/-1     
    mod.rs
    Introduce HTTP bridge module.                                                       

    bongonet-core/src/protocols/http/bridge/mod.rs

    • Added a new module for HTTP bridge functionalities.
    +15/-0   
    Documentation
    23 files
    grpc_web_module.rs
    Add example for gRPC-web bridge module usage.                       

    bongonet-proxy/examples/grpc_web_module.rs

  • Added an example for using the gRPC-web bridge module.
  • Demonstrated initialization and usage of the gRPC-web module in a
    proxy.
  • +90/-0   
    mod.rs
    Add documentation for modules in bongonet.                             

    bongonet-core/src/modules/mod.rs

    • Added documentation for modules.
    +3/-1     
    quick_start.md
    Improve formatting and readability in quick_start.md         

    docs/quick_start.md

  • Added missing newlines for better readability.
  • Corrected minor formatting issues.
  • +38/-28 
    phase.md
    Improve formatting and readability in phase.md                     

    docs/user_guide/phase.md

  • Added missing newlines for better readability.
  • Corrected minor formatting issues.
  • +25/-7   
    CHANGELOG.md
    Update CHANGELOG with detailed entries for past versions 

    CHANGELOG.md

  • Added detailed changelog entries for versions 0.1.0 to 0.3.0.
  • Documented new features, bug fixes, and changes.
  • +108/-0 
    README.md
    Enhance README formatting and add feature details               

    README.md

  • Improved formatting and readability.
  • Added additional information about Bongonet features.
  • +36/-26 
    rate_limiter.md
    Add RateLimiter quickstart guide with examples                     

    docs/user_guide/rate_limiter.md

  • Added a new section for RateLimiter quickstart.
  • Provided example code and testing instructions.
  • +60/-5   
    conf.md
    Enhance formatting in configuration guide                               

    docs/user_guide/conf.md

  • Improved formatting of the configuration settings table.
  • Added missing newlines for better readability.
  • +19/-15 
    internals.md
    Improve formatting and readability in internals.md             

    docs/user_guide/internals.md

  • Corrected minor formatting issues.
  • Improved readability by adding missing newlines.
  • +12/-13 
    index.md
    Enhance formatting and structure in user guide index         

    docs/user_guide/index.md

  • Improved formatting and readability.
  • Added missing newlines for better structure.
  • +26/-23 
    failover.md
    Improve formatting and readability in failover.md               

    docs/user_guide/failover.md

  • Added missing newlines for better readability.
  • Corrected minor formatting issues.
  • +4/-1     
    start_stop.md
    Enhance formatting in start and stop guide                             

    docs/user_guide/start_stop.md

  • Improved formatting of command-line arguments table.
  • Added missing newlines for better readability.
  • +11/-6   
    error_log.md
    Enhance formatting in error log guide                                       

    docs/user_guide/error_log.md

  • Improved formatting of log level guidelines.
  • Added missing newlines for better readability.
  • +7/-5     
    ctx.md
    Improve formatting and readability in ctx.md                         

    docs/user_guide/ctx.md

  • Added missing newlines for better readability.
  • Corrected minor formatting issues.
  • +5/-2     
    modify_filter.md
    Improve formatting and readability in modify_filter.md     

    docs/user_guide/modify_filter.md

  • Added missing newlines for better readability.
  • Corrected minor formatting issues.
  • +4/-4     
    graceful.md
    Improve formatting and readability in graceful.md               

    docs/user_guide/graceful.md

  • Added missing newlines for better readability.
  • Corrected minor formatting issues.
  • +7/-2     
    CONTRIBUTING.md
    Enhance formatting in contributing guidelines                       

    .github/CONTRIBUTING.md

  • Improved formatting and readability.
  • Added missing newlines for better structure.
  • +4/-3     
    errors.md
    Improve formatting and readability in errors.md                   

    docs/user_guide/errors.md

  • Added missing newlines for better readability.
  • Corrected minor formatting issues.
  • +3/-2     
    pooling.md
    Improve formatting and readability in pooling.md                 

    docs/user_guide/pooling.md

  • Added missing newlines for better readability.
  • Corrected minor formatting issues.
  • +12/-8   
    README.md
    Improve formatting in docs README                                               

    docs/README.md

    • Added missing newlines for better readability.
    +3/-0     
    panic.md
    Improve formatting in panic guide                                               

    docs/user_guide/panic.md

    • Added missing newlines for better readability.
    +1/-0     
    bug_report.md
    Enhance formatting in bug report template                               

    .github/ISSUE_TEMPLATE/bug_report.md

    • Improved formatting and readability.
    +3/-3     
    phase_chart.md
    Improve formatting in phase_chart.md                                         

    docs/user_guide/phase_chart.md

    • Added missing newline for better readability.
    +1/-0     
    Tests
    2 files
    test_upstream.rs
    Add test for multiple streaming writers in cache.               

    bongonet-proxy/tests/test_upstream.rs

  • Added a test for multiple streaming writers in cache.
  • Ensured no conflict occurs with multiple writers.
  • +38/-4   
    lib.rs
    Adjust sleep durations in runtime tests.                                 

    bongonet-runtime/src/lib.rs

    • Adjusted sleep durations in test for better timing.
    +4/-9     
    Formatting
    29 files
    l4.rs
    Improve import order in L4 listener module.                           

    bongonet-core/src/listeners/l4.rs

    • Reorganized imports for better readability.
    +3/-3     
    v2.rs
    Improve import order in HTTP/2 connector.                               

    bongonet-core/src/connectors/http/v2.rs

    • Reorganized imports for better readability.
    +4/-4     
    mod.rs
    Improve import order in connectors module.                             

    bongonet-core/src/connectors/mod.rs

    • Reorganized imports for better readability.
    +3/-3     
    mod.rs
    Improve import order in TLS listener module.                         

    bongonet-core/src/listeners/tls/boringssl_openssl/mod.rs

    • Reorganized imports for better readability.
    +2/-2     
    client.rs
    Improve import order in HTTP/2 client module.                       

    bongonet-core/src/protocols/http/v2/client.rs

    • Reorganized imports for better readability.
    +4/-4     
    mod.rs
    Improve import order in TLS connector module.                       

    bongonet-core/src/connectors/tls/boringssl_openssl/mod.rs

    • Reorganized imports for better readability.
    +2/-2     
    http_app.rs
    Improve import order in HTTP app module.                                 

    bongonet-core/src/apps/http_app.rs

    • Reorganized imports for better readability.
    +2/-2     
    l4.rs
    Improve import order in L4 connector module.                         

    bongonet-core/src/connectors/l4.rs

    • Reorganized imports for better readability.
    +2/-2     
    client.rs
    Improve import order in HTTP/1.x client module.                   

    bongonet-core/src/protocols/http/v1/client.rs

    • Reorganized imports for better readability.
    +4/-4     
    server.rs
    Improve import order in HTTP server module.                           

    bongonet-core/src/protocols/http/server.rs

    • Reorganized imports for better readability.
    +3/-3     
    mod.rs
    Improve import order in test utilities.                                   

    bongonet-core/tests/utils/mod.rs

    • Reorganized imports for better readability.
    +3/-3     
    body.rs
    Improve import order in HTTP/1.x body module.                       

    bongonet-core/src/protocols/http/v1/body.rs

    • Reorganized imports for better readability.
    +3/-3     
    conditional_filter.rs
    Improve import order in conditional filter module.             

    bongonet-core/src/protocols/http/conditional_filter.rs

    • Reorganized imports for better readability.
    +3/-3     
    server.rs
    Improve import order in HTTP/2 server module.                       

    bongonet-core/src/protocols/http/v2/server.rs

    • Reorganized imports for better readability.
    +2/-2     
    mod.rs
    Improve import order in TLS module.                                           

    bongonet-core/src/protocols/tls/mod.rs

    • Reorganized imports for better readability.
    +2/-2     
    mod.rs
    Improve import order in utils module.                                       

    bongonet-core/src/utils/mod.rs

    • Reorganized imports for better readability.
    +2/-2     
    ext.rs
    Improve import order in L4 extension module.                         

    bongonet-core/src/protocols/l4/ext.rs

    • Reorganized imports for better readability.
    +2/-2     
    mod.rs
    Improve import order in server module.                                     

    bongonet-core/src/server/mod.rs

    • Reorganized imports for better readability.
    +3/-3     
    stream.rs
    Improve import order in L4 stream module.                               

    bongonet-core/src/protocols/l4/stream.rs

    • Reorganized imports for better readability.
    +2/-2     
    zstd.rs
    Improve import order in Zstd compression module.                 

    bongonet-core/src/protocols/http/compression/zstd.rs

    • Reorganized imports for better readability.
    +2/-2     
    listening.rs
    Improve import order in listening service module.               

    bongonet-core/src/services/listening.rs

    • Reorganized imports for better readability.
    +2/-2     
    brotli.rs
    Improve import order in Brotli compression module.             

    bongonet-core/src/protocols/http/compression/brotli.rs

    • Reorganized imports for better readability.
    +2/-2     
    load_balancer.rs
    Improve import order in load balancer example.                     

    bongonet-proxy/examples/load_balancer.rs

    • Reorganized imports for better readability.
    +2/-2     
    client.rs
    Improve import order in HTTP client module.                           

    bongonet-core/src/protocols/http/client.rs

    • Reorganized imports for better readability.
    +2/-2     
    gzip.rs
    Improve import order in Gzip compression module.                 

    bongonet-core/src/protocols/http/compression/gzip.rs

    • Reorganized imports for better readability.
    +2/-2     
    mod.rs
    Improve import order in server configuration module.         

    bongonet-core/src/server/configuration/mod.rs

    • Reorganized imports for better readability.
    +2/-2     
    mod.rs
    Improve import order in HTTP compression module.                 

    bongonet-core/src/protocols/http/compression/mod.rs

    • Reorganized imports for better readability.
    +3/-3     
    common.rs
    Improve import order in HTTP/1.x common module.                   

    bongonet-core/src/protocols/http/v1/common.rs

    • Reorganized imports for better readability.
    +2/-2     
    error_resp.rs
    Improve import order in error response module.                     

    bongonet-core/src/protocols/http/error_resp.rs

    • Reorganized imports for better readability.
    +2/-2     
    Miscellaneous
    108 files
    peer.rs
    Update copyright notice in upstream peer module.                 

    bongonet-core/src/upstreams/peer.rs

    • Corrected the company name in the copyright notice.
    +1/-6     
    boring_tokio.rs
    Update copyright notice in boring_tokio module.                   

    bongonet-boringssl/src/boring_tokio.rs

    • Corrected the company name in the copyright notice.
    +1/-1     
    lru_serde.rs
    Update copyright notice in lru_serde benchmark.                   

    bongonet-cache/benches/lru_serde.rs

    • Corrected the company name in the copyright notice.
    +1/-1     
    simple_lru_memory.rs
    Update copyright notice in simple_lru_memory benchmark.   

    bongonet-cache/benches/simple_lru_memory.rs

    • Corrected the company name in the copyright notice.
    +1/-1     
    simple_lru.rs
    Update copyright notice in simple_lru eviction module.     

    bongonet-cache/src/eviction/simple_lru.rs

    • Corrected the company name in the copyright notice.
    +1/-1     
    lru_memory.rs
    Update copyright notice in lru_memory benchmark.                 

    bongonet-cache/benches/lru_memory.rs

    • Corrected the company name in the copyright notice.
    +1/-1     
    lru.rs
    Update copyright notice in lru eviction module.                   

    bongonet-cache/src/eviction/lru.rs

    • Corrected the company name in the copyright notice.
    +1/-1     
    prometheus_http_app.rs
    Update copyright notice in Prometheus HTTP app.                   

    bongonet-core/src/apps/prometheus_http_app.rs

    • Corrected the company name in the copyright notice.
    +1/-1     
    v1.rs
    Update copyright notice in HTTP/1 connector.                         

    bongonet-core/src/connectors/http/v1.rs

    • Corrected the company name in the copyright notice.
    +1/-1     
    mod.rs
    Update copyright notice in eviction module.                           

    bongonet-cache/src/eviction/mod.rs

    • Corrected the company name in the copyright notice.
    +1/-1     
    mod.rs
    Update copyright notice in HTTP connectors module.             

    bongonet-core/src/connectors/http/mod.rs

    • Corrected the company name in the copyright notice.
    +1/-1     
    offload.rs
    Update copyright notice in offload connector.                       

    bongonet-core/src/connectors/offload.rs

    • Corrected the company name in the copyright notice.
    +1/-1     
    compression.rs
    Update copyright notice in HTTP compression module.           

    bongonet-core/src/modules/http/compression.rs

    • Corrected the company name in the copyright notice.
    +1/-1     
    ext.rs
    Update copyright notice in BoringSSL extension module.     

    bongonet-boringssl/src/ext.rs

    • Corrected the company name in the copyright notice.
    +1/-1     
    lib.rs
    Update copyright notice in BoringSSL library.                       

    bongonet-boringssl/src/lib.rs

    • Corrected the company name in the copyright notice.
    +1/-1     
    hashtable.rs
    Update copyright notice in hashtable module.                         

    bongonet-cache/src/hashtable.rs

    • Corrected the company name in the copyright notice.
    +1/-1     
    predictor.rs
    Update copyright notice in predictor module.                         

    bongonet-cache/src/predictor.rs

    • Corrected the company name in the copyright notice.
    +1/-1     
    mod.rs
    Update copyright notice in listeners module.                         

    bongonet-core/src/listeners/mod.rs

    • Corrected the company name in the copyright notice.
    +1/-1     
    filters.rs
    Update copyright notice in filters module.                             

    bongonet-cache/src/filters.rs

    • Corrected the company name in the copyright notice.
    +1/-1     
    put.rs
    Update copyright notice in put module.                                     

    bongonet-cache/src/put.rs

    • Corrected the company name in the copyright notice.
    +1/-1     
    trace.rs
    Update copyright notice in trace module.                                 

    bongonet-cache/src/trace.rs

    • Corrected the company name in the copyright notice.
    +1/-1     
    mod.rs
    Update copyright notice in apps module.                                   

    bongonet-core/src/apps/mod.rs

    • Corrected the company name in the copyright notice.
    +1/-1     
    key.rs
    Update copyright notice in key module.                                     

    bongonet-cache/src/key.rs

    • Corrected the company name in the copyright notice.
    +1/-1     
    meta.rs
    Update copyright notice in meta module.                                   

    bongonet-cache/src/meta.rs

    • Corrected the company name in the copyright notice.
    +1/-1     
    lib.rs
    Update copyright notice in core library.                                 

    bongonet-core/src/lib.rs

    • Corrected the company name in the copyright notice.
    +1/-1     
    client.rs
    Update copyright notice in TLS client module.                       

    bongonet-core/src/protocols/tls/boringssl_openssl/client.rs

    • Corrected the company name in the copyright notice.
    +1/-1     
    mod.rs
    Update copyright notice in dummy TLS module.                         

    bongonet-core/src/protocols/tls/dummy_tls/mod.rs

    • Corrected the company name in the copyright notice.
    +1/-1     
    bench_linked_list.rs
    Update copyright notice in linked list benchmark.               

    bongonet-lru/benches/bench_linked_list.rs

    • Corrected the company name in the copyright notice.
    +1/-1     
    bench_lru.rs
    Update copyright notice in LRU benchmark.                               

    bongonet-lru/benches/bench_lru.rs

    • Corrected the company name in the copyright notice.
    +1/-1     
    mod.rs
    Update copyright notice in HTTP/1.x module.                           

    bongonet-core/src/protocols/http/v1/mod.rs

    • Corrected the company name in the copyright notice.
    +1/-1     
    mod.rs
    Update copyright notice in HTTP/2 module.                               

    bongonet-core/src/protocols/http/v2/mod.rs

    • Corrected the company name in the copyright notice.
    +1/-1     
    listener.rs
    Update copyright notice in L4 listener module.                     

    bongonet-core/src/protocols/l4/listener.rs

    • Corrected the company name in the copyright notice.
    +1/-1     
    digest.rs
    Update copyright notice in TLS digest module.                       

    bongonet-core/src/protocols/tls/digest.rs

    • Corrected the company name in the copyright notice.
    +1/-1     
    algorithms.rs
    Update copyright notice in selection algorithms module.   

    bongonet-load-balancing/src/selection/algorithms.rs

    • Corrected the company name in the copyright notice.
    +1/-1     
    consistent.rs
    Update copyright notice in consistent selection module.   

    bongonet-load-balancing/src/selection/consistent.rs

    • Corrected the company name in the copyright notice.
    +1/-1     
    weighted.rs
    Update copyright notice in weighted selection module.       

    bongonet-load-balancing/src/selection/weighted.rs

    • Corrected the company name in the copyright notice.
    +1/-1     
    body_buffer.rs
    Update copyright notice in HTTP body buffer module.           

    bongonet-core/src/protocols/http/body_buffer.rs

    • Corrected the company name in the copyright notice.
    +1/-1     
    mod.rs
    Update copyright notice in L4 module.                                       

    bongonet-core/src/protocols/l4/mod.rs

    • Corrected the company name in the copyright notice.
    +1/-1     
    socket.rs
    Update copyright notice in L4 socket module.                         

    bongonet-core/src/protocols/l4/socket.rs

    • Corrected the company name in the copyright notice.
    +1/-1     
    mod.rs
    Update copyright notice in transfer_fd module.                     

    bongonet-core/src/server/transfer_fd/mod.rs

    • Corrected the company name in the copyright notice.
    +1/-1     
    thread_zstd.rs
    Update copyright notice in thread_zstd module.                     

    bongonet-header-serde/src/thread_zstd.rs

    • Corrected the company name in the copyright notice.
    +1/-1     
    benchmark.rs
    Update copyright notice in limits benchmark.                         

    bongonet-limits/benches/benchmark.rs

    • Corrected the company name in the copyright notice.
    +1/-1     
    health_check.rs
    Update copyright notice in health check module.                   

    bongonet-load-balancing/src/health_check.rs

    • Corrected the company name in the copyright notice.
    +1/-1     
    mod.rs
    Update copyright notice in selection module.                         

    bongonet-load-balancing/src/selection/mod.rs

    • Corrected the company name in the copyright notice.
    +1/-1     
    benchmark.rs
    Update copyright notice in timeout benchmark.                       

    bongonet-timeout/benches/benchmark.rs

    • Corrected the company name in the copyright notice.
    +1/-1     
    bench_hit_ratio.rs
    Update copyright notice in hit ratio benchmark.                   

    tinyufo/benches/bench_hit_ratio.rs

    • Corrected the company name in the copyright notice.
    +1/-1     
    digest.rs
    Update copyright notice in digest module.                               

    bongonet-core/src/protocols/digest.rs

    • Corrected the company name in the copyright notice.
    +1/-1     
    date.rs
    Update copyright notice in HTTP date module.                         

    bongonet-core/src/protocols/http/date.rs

    • Corrected the company name in the copyright notice.
    +1/-1     
    dict.rs
    Update copyright notice in dict module.                                   

    bongonet-header-serde/src/dict.rs

    • Corrected the company name in the copyright notice.
    +1/-1     
    trainer.rs
    Update copyright notice in trainer module.                             

    bongonet-header-serde/src/trainer.rs

    • Corrected the company name in the copyright notice.
    +1/-1     
    case_header_name.rs
    Update copyright notice in case header name module.           

    bongonet-http/src/case_header_name.rs

    • Corrected the company name in the copyright notice.
    +1/-1     
    estimator.rs
    Update copyright notice in estimator module.                         

    bongonet-limits/src/estimator.rs

    • Corrected the company name in the copyright notice.
    +1/-1     
    discovery.rs
    Update copyright notice in discovery module.                         

    bongonet-load-balancing/src/discovery.rs

    • Corrected the company name in the copyright notice.
    +1/-1     
    linked_list.rs
    Update copyright notice in linked list module.                     

    bongonet-lru/src/linked_list.rs

    • Corrected the company name in the copyright notice.
    +1/-1     
    proxy_h1.rs
    Update copyright notice in HTTP/1 proxy module.                   

    bongonet-proxy/src/proxy_h1.rs

    • Corrected the company name in the copyright notice.
    +1/-1     
    proxy_purge.rs
    Update copyright notice in proxy purge module.                     

    bongonet-proxy/src/proxy_purge.rs

    • Corrected the company name in the copyright notice.
    +1/-1     
    hello.rs
    Update copyright notice in hello benchmark.                           

    bongonet-runtime/benches/hello.rs

    • Corrected the company name in the copyright notice.
    +1/-1     
    bench_memory.rs
    Update copyright notice in memory benchmark.                         

    tinyufo/benches/bench_memory.rs

    • Corrected the company name in the copyright notice.
    +1/-1     
    bench_perf.rs
    Update copyright notice in performance benchmark.               

    tinyufo/benches/bench_perf.rs

    • Corrected the company name in the copyright notice.
    +1/-1     
    mod.rs
    Update copyright notice in protocols module.                         

    bongonet-core/src/protocols/mod.rs

    • Corrected the company name in the copyright notice.
    +1/-1     
    daemon.rs
    Fix copyright notice company name in daemon.rs                     

    bongonet-core/src/server/daemon.rs

    • Corrected the company name in the copyright notice.
    +1/-1     
    mod.rs
    Fix copyright notice company name in tls/mod.rs                   

    bongonet-core/src/tls/mod.rs

    • Corrected the company name in the copyright notice.
    +1/-1     
    mod.rs
    Fix copyright notice company name in upstreams/mod.rs       

    bongonet-core/src/upstreams/mod.rs

    • Corrected the company name in the copyright notice.
    +1/-1     
    immut_str.rs
    Fix copyright notice company name in immut_str.rs               

    bongonet-error/src/immut_str.rs

    • Corrected the company name in the copyright notice.
    +1/-1     
    lib.rs
    Fix copyright notice company name in header-serde/lib.rs 

    bongonet-header-serde/src/lib.rs

    • Corrected the company name in the copyright notice.
    +1/-1     
    lib.rs
    Fix copyright notice company name in ketama/lib.rs             

    bongonet-ketama/src/lib.rs

    • Corrected the company name in the copyright notice.
    +1/-1     
    inflight.rs
    Fix copyright notice company name in limits/inflight.rs   

    bongonet-limits/src/inflight.rs

    • Corrected the company name in the copyright notice.
    +1/-1     
    background.rs
    Fix copyright notice company name in load-balancing/background.rs

    bongonet-load-balancing/src/background.rs

    • Corrected the company name in the copyright notice.
    +1/-1     
    lib.rs
    Fix copyright notice company name in load-balancing/lib.rs

    bongonet-load-balancing/src/lib.rs

    • Corrected the company name in the copyright notice.
    +1/-1     
    read_through.rs
    Fix copyright notice company name in memory-cache/read_through.rs

    bongonet-memory-cache/src/read_through.rs

    • Corrected the company name in the copyright notice.
    +1/-1     
    lru.rs
    Fix copyright notice company name in pool/lru.rs                 

    bongonet-pool/src/lru.rs

    • Corrected the company name in the copyright notice.
    +1/-1     
    modify_response.rs
    Fix copyright notice company name in proxy/examples/modify_response.rs

    bongonet-proxy/examples/modify_response.rs

    • Corrected the company name in the copyright notice.
    +1/-1     
    multi_lb.rs
    Fix copyright notice company name in proxy/examples/multi_lb.rs

    bongonet-proxy/examples/multi_lb.rs

    • Corrected the company name in the copyright notice.
    +1/-1     
    proxy_cache.rs
    Fix copyright notice company name in proxy/src/proxy_cache.rs

    bongonet-proxy/src/proxy_cache.rs

    • Corrected the company name in the copyright notice.
    +1/-1     
    proxy_trait.rs
    Fix copyright notice company name in proxy/src/proxy_trait.rs

    bongonet-proxy/src/proxy_trait.rs

    • Corrected the company name in the copyright notice.
    +1/-1     
    cert.rs
    Fix copyright notice company name in proxy/tests/utils/cert.rs

    bongonet-proxy/tests/utils/cert.rs

    • Corrected the company name in the copyright notice.
    +1/-1     
    mock_origin.rs
    Fix copyright notice company name in proxy/tests/utils/mock_origin.rs

    bongonet-proxy/tests/utils/mock_origin.rs

    • Corrected the company name in the copyright notice.
    +1/-1     
    fast_timeout.rs
    Fix copyright notice company name in timeout/fast_timeout.rs

    bongonet-timeout/src/fast_timeout.rs

    • Corrected the company name in the copyright notice.
    +1/-1     
    timer.rs
    Fix copyright notice company name in timeout/timer.rs       

    bongonet-timeout/src/timer.rs

    • Corrected the company name in the copyright notice.
    +1/-1     
    background.rs
    Fix copyright notice company name in services/background.rs

    bongonet-core/src/services/background.rs

    • Corrected the company name in the copyright notice.
    +1/-1     
    mod.rs
    Fix copyright notice company name in services/mod.rs         

    bongonet-core/src/services/mod.rs

    • Corrected the company name in the copyright notice.
    +1/-1     
    test_basic.rs
    Fix copyright notice company name in core/tests/test_basic.rs

    bongonet-core/tests/test_basic.rs

    • Corrected the company name in the copyright notice.
    +1/-1     
    lib.rs
    Fix copyright notice company name in limits/lib.rs             

    bongonet-limits/src/lib.rs

    • Corrected the company name in the copyright notice.
    +1/-1     
    lib.rs
    Fix copyright notice company name in lru/lib.rs                   

    bongonet-lru/src/lib.rs

    • Corrected the company name in the copyright notice.
    +1/-1     
    lib.rs
    Fix copyright notice company name in memory-cache/lib.rs 

    bongonet-memory-cache/src/lib.rs

    • Corrected the company name in the copyright notice.
    +1/-1     
    ext.rs
    Fix copyright notice company name in openssl/ext.rs           

    bongonet-openssl/src/ext.rs

    • Corrected the company name in the copyright notice.
    +1/-1     
    lib.rs
    Fix copyright notice company name in openssl/lib.rs           

    bongonet-openssl/src/lib.rs

    • Corrected the company name in the copyright notice.
    +1/-1     
    connection.rs
    Fix copyright notice company name in pool/connection.rs   

    bongonet-pool/src/connection.rs

    • Corrected the company name in the copyright notice.
    +1/-1     
    lib.rs
    Fix copyright notice company name in pool/lib.rs                 

    bongonet-pool/src/lib.rs

    • Corrected the company name in the copyright notice.
    +1/-1     
    ctx.rs
    Fix copyright notice company name in proxy/examples/ctx.rs

    bongonet-proxy/examples/ctx.rs

    • Corrected the company name in the copyright notice.
    +1/-1     
    use_module.rs
    Fix copyright notice company name in proxy/examples/use_module.rs

    bongonet-proxy/examples/use_module.rs

    • Corrected the company name in the copyright notice.
    +1/-1     
    subrequest.rs
    Fix copyright notice company name in proxy/src/subrequest.rs

    bongonet-proxy/src/subrequest.rs

    • Corrected the company name in the copyright notice.
    +1/-1     
    test_basic.rs
    Fix copyright notice company name in proxy/tests/test_basic.rs

    bongonet-proxy/tests/test_basic.rs

    • Corrected the company name in the copyright notice.
    +1/-1     
    mod.rs
    Fix copyright notice company name in proxy/tests/utils/mod.rs

    bongonet-proxy/tests/utils/mod.rs

    • Corrected the company name in the copyright notice.
    +1/-1     
    lib.rs
    Fix copyright notice company name in timeout/lib.rs           

    bongonet-timeout/src/lib.rs

    • Corrected the company name in the copyright notice.
    +1/-1     
    echo.rs
    Fix copyright notice company name in examples/app/echo.rs

    bongonet/examples/app/echo.rs

    • Corrected the company name in the copyright notice.
    +1/-1     
    proxy.rs
    Fix copyright notice company name in examples/app/proxy.rs

    bongonet/examples/app/proxy.rs

    • Corrected the company name in the copyright notice.
    +1/-1     
    echo.rs
    Fix copyright notice company name in examples/service/echo.rs

    bongonet/examples/service/echo.rs

    • Corrected the company name in the copyright notice.
    +1/-1     
    proxy.rs
    Fix copyright notice company name in examples/service/proxy.rs

    bongonet/examples/service/proxy.rs

    • Corrected the company name in the copyright notice.
    +1/-1     
    estimation.rs
    Fix copyright notice company name in tinyufo/estimation.rs

    tinyufo/src/estimation.rs

    • Corrected the company name in the copyright notice.
    +1/-1     
    lib.rs
    Fix copyright notice company name in error/lib.rs               

    bongonet-error/src/lib.rs

    • Corrected the company name in the copyright notice.
    +1/-1     
    mod.rs
    Fix copyright notice company name in examples/app/mod.rs 

    bongonet/examples/app/mod.rs

    • Corrected the company name in the copyright notice.
    +1/-1     
    mod.rs
    Fix copyright notice company name in examples/service/mod.rs

    bongonet/examples/service/mod.rs

    • Corrected the company name in the copyright notice.
    +1/-1     
    buckets.rs
    Fix copyright notice company name in tinyufo/buckets.rs   

    tinyufo/src/buckets.rs

    • Corrected the company name in the copyright notice.
    +1/-1     
    client.rs
    Fix copyright notice company name in examples/client.rs   

    bongonet/examples/client.rs

    • Corrected the company name in the copyright notice.
    +1/-1     
    server.rs
    Fix copyright notice company name in examples/server.rs   

    bongonet/examples/server.rs

    • Corrected the company name in the copyright notice.
    +1/-1     
    lib.rs
    Fix copyright notice company name in src/lib.rs                   

    bongonet/src/lib.rs

    • Corrected the company name in the copyright notice.
    +1/-1     
    lib.rs
    Fix copyright notice company name in tinyufo/lib.rs           

    tinyufo/src/lib.rs

    • Corrected the company name in the copyright notice.
    +1/-1     
    Bug fix
    1 files
    gateway.rs
    Fix metric name in gateway example.                                           

    bongonet-proxy/examples/gateway.rs

    • Corrected metric name from reg_counter to req_counter.
    +2/-2     
    Configuration changes
    5 files
    bongonet_conf.yaml
    Add configuration file for bongonet tests.                             

    bongonet-core/tests/bongonet_conf.yaml

    • Added a new configuration file for bongonet tests.
    +6/-1     
    build.yml
    Update Rust toolchain and adjust build conditions               

    .github/workflows/build.yml

  • Updated Rust toolchain version in the build matrix.
  • Adjusted conditions for running cargo clippy and audit.
  • +3/-3     
    semgrep.yml
    Add Semgrep analysis workflow for code scanning                   

    .github/workflows/semgrep.yml

  • Added a new workflow for Semgrep analysis.
  • Configured to run on specific branches and events.
  • +24/-0   
    nginx.conf
    Update Lua script in nginx configuration                                 

    bongonet-proxy/tests/utils/conf/origin/conf/nginx.conf

    • Modified Lua script to use a variable for output.
    +2/-1     
    .bleep
    Update hash value in .bleep                                                           

    .bleep

    • Updated the hash value.
    +1/-1     
    Dependencies
    17 files
    Cargo.toml
    Update authorship and formatting in proxy/Cargo.toml         

    bongonet-proxy/Cargo.toml

  • Updated authorship information.
  • Added newline at the end of the file.
  • +2/-2     
    Cargo.toml
    Update authorship and add dependency in cache/Cargo.toml 

    bongonet-cache/Cargo.toml

  • Updated authorship information.
  • Added a new dependency on strum for deriving features.
  • +2/-1     
    Cargo.toml
    Update authorship in boringssl/Cargo.toml                               

    bongonet-boringssl/Cargo.toml

    • Updated authorship information.
    +1/-1     
    Cargo.toml
    Update authorship in core/Cargo.toml                                         

    bongonet-core/Cargo.toml

    • Updated authorship information.
    +1/-1     
    Cargo.toml
    Update authorship in tinyufo/Cargo.toml                                   

    tinyufo/Cargo.toml

    • Updated authorship information.
    +1/-1     
    Cargo.toml
    Update authorship in header-serde/Cargo.toml                         

    bongonet-header-serde/Cargo.toml

    • Updated authorship information.
    +1/-1     
    Cargo.toml
    Update authorship in load-balancing/Cargo.toml                     

    bongonet-load-balancing/Cargo.toml

    • Updated authorship information.
    +1/-1     
    Cargo.toml
    Update authorship in lru/Cargo.toml                                           

    bongonet-lru/Cargo.toml

    • Updated authorship information.
    +1/-1     
    Cargo.toml
    Update authorship in memory-cache/Cargo.toml                         

    bongonet-memory-cache/Cargo.toml

    • Updated authorship information.
    +1/-1     
    Cargo.toml
    Update authorship in openssl/Cargo.toml                                   

    bongonet-openssl/Cargo.toml

    • Updated authorship information.
    +1/-1     
    Cargo.toml
    Update authorship in pool/Cargo.toml                                         

    bongonet-pool/Cargo.toml

    • Updated authorship information.
    +1/-1     
    Cargo.toml
    Update authorship in timeout/Cargo.toml                                   

    bongonet-timeout/Cargo.toml

    • Updated authorship information.
    +1/-1     
    Cargo.toml
    Update authorship in error/Cargo.toml                                       

    bongonet-error/Cargo.toml

    • Updated authorship information.
    +1/-1     
    Cargo.toml
    Update authorship in http/Cargo.toml                                         

    bongonet-http/Cargo.toml

    • Updated authorship information.
    +1/-1     
    Cargo.toml
    Update authorship in runtime/Cargo.toml                                   

    bongonet-runtime/Cargo.toml

    • Updated authorship information.
    +1/-1     
    Cargo.toml
    Update authorship in limits/Cargo.toml                                     

    bongonet-limits/Cargo.toml

    • Updated authorship information.
    +1/-1     
    Cargo.toml
    Update authorship in bongonet/Cargo.toml                                 

    bongonet/Cargo.toml

    • Updated authorship information.
    +1/-1     

    💡 PR-Agent usage: Comment /help "your question" on any pull request to receive relevant information

    Copy link

    sourcery-ai bot commented Sep 27, 2024

    Reviewer's Guide by Sourcery

    This pull request introduces support for gRPC-web in Bongonet. It adds a new module to bridge gRPC-web requests to gRPC requests, allowing Bongonet to act as a proxy between gRPC-web clients and gRPC servers. The changes include new files for the gRPC-web bridge implementation, modifications to existing HTTP protocol handling, and updates to various documentation and examples. Additionally, there are widespread changes to update copyright notices and some minor refactoring and cleanup.

    Sequence Diagram

    sequenceDiagram
        participant Client as gRPC-web Client
        participant Bongonet as Bongonet Proxy
        participant Server as gRPC Server
    
        Client->>Bongonet: gRPC-web Request
        Bongonet->>Bongonet: Convert to gRPC
        Bongonet->>Server: gRPC Request
        Server->>Bongonet: gRPC Response
        Bongonet->>Bongonet: Convert to gRPC-web
        Bongonet->>Client: gRPC-web Response
    
    Loading

    File-Level Changes

    Change Details Files
    Add gRPC-web bridge module
    • Implement GrpcWebCtx for handling gRPC-web protocol conversion
    • Create GrpcWebBridge and GrpcWeb module types
    • Add new example for gRPC-web module usage
    • Update HTTP protocol handling to support gRPC-web conversion
    bongonet-core/src/protocols/http/bridge/grpc_web.rs
    bongonet-core/src/modules/http/grpc_web.rs
    bongonet-proxy/examples/grpc_web_module.rs
    bongonet-core/src/protocols/http/mod.rs
    Update copyright notices
    • Change copyright holder from 'Khulnasoft, Ltd.' to 'KhulnaSoft, Ltd.'
    • Update year in copyright notices to 2024
    Multiple files across the repository
    Refactor and improve existing code
    • Modify RequestHeader to support controlling END_STREAM flag for H2 requests
    • Update HTTP cache implementation to handle streaming writes
    • Improve error handling and logging in various components
    bongonet-http/src/lib.rs
    bongonet-cache/src/storage.rs
    bongonet-cache/src/lib.rs
    bongonet-core/src/protocols/http/v1/server.rs
    Update documentation and examples
    • Add new example for gRPC-web module usage
    • Update README and user guide documentation
    • Improve formatting and clarity in various documentation files
    bongonet-proxy/examples/grpc_web_module.rs
    README.md
    docs/user_guide/*.md
    Add Semgrep configuration for code analysis
    • Create new GitHub Actions workflow for Semgrep
    .github/workflows/semgrep.yml

    Tips and commands

    Interacting with Sourcery

    • Trigger a new review: Comment @sourcery-ai review on the pull request.
    • Continue discussions: Reply directly to Sourcery's review comments.
    • Generate a GitHub issue from a review comment: Ask Sourcery to create an
      issue from a review comment by replying to it.

    Customizing Your Experience

    Access your dashboard to:

    • Enable or disable review features such as the Sourcery-generated pull request
      summary, the reviewer's guide, and others.
    • Change the review language.
    • Add, remove or edit custom review instructions.
    • Adjust other review settings.

    Getting Help

    Copy link

    @sourcery-ai sourcery-ai bot left a comment

    Choose a reason for hiding this comment

    The reason will be displayed to describe this comment to others. Learn more.

    We have skipped reviewing this pull request. It seems to have been created by a bot (hey, khulnasoft-bot!). We assume it knows what it's doing!

    Copy link

    PR Reviewer Guide 🔍

    ⏱️ Estimated effort to review: 4 🔵🔵🔵🔵⚪
    🧪 PR contains tests
    🔒 No security concerns identified
    ⚡ Key issues to review

    New Feature
    New gRPC-web bridging module added. This introduces functionality to convert between gRPC-web and gRPC protocols. Careful review needed to ensure correct protocol conversion and handling of edge cases.

    Concurrency Changes
    Significant changes to support multiple concurrent writers for streaming write tags. This could introduce race conditions or synchronization issues if not implemented correctly.

    API Change
    New lookup_streaming_write method added to the Storage trait. This changes the storage API and could affect existing implementations.

    Copy link

    PR Code Suggestions ✨

    Explore these optional code suggestions:

    CategorySuggestion                                                                                                                                    Score
    Performance
    Optimize span creation in cache_lock_wait method

    In the cache_lock_wait method, consider moving the span creation after the lock
    check to avoid unnecessary span creation when there's no lock. This can potentially
    improve performance by reducing the number of spans created.

    bongonet-cache/src/lib.rs [1059-1061]

    -let mut span = inner.traces.child("cache_lock");
     let lock = inner.lock.take(); // remove the lock from self
     if let Some(Locked::Read(r)) = lock {
    +    let mut span = inner.traces.child("cache_lock");
    • Apply this suggestion
    Suggestion importance[1-10]: 8

    Why: Moving span creation after the lock check can improve performance by avoiding unnecessary span creation, which is beneficial in scenarios where the lock is not held.

    8
    Use BytesMut::extend_from_slice() consistently for better performance and readability

    Consider using BytesMut::extend_from_slice() instead of BytesMut::put_slice() for
    consistency and to potentially improve performance, as it may reduce the number of
    method calls.

    bongonet-core/src/protocols/http/bridge/grpc_web.rs [175-177]

    -buf.put_u8(GRPC_WEB_TRAILER);
    -buf.put_u32(len);
    +buf.extend_from_slice(&[GRPC_WEB_TRAILER]);
    +buf.extend_from_slice(&len.to_be_bytes());
     buf.unsplit(trailers);
    • Apply this suggestion
    Suggestion importance[1-10]: 5

    Why: Switching to extend_from_slice() for consistency and potential performance improvement is a minor enhancement. The impact on performance and readability is minimal, but it aligns with best practices.

    5
    Error handling
    Use the ? operator for error handling instead of expect() to allow for more graceful error propagation

    Consider using the ? operator instead of expect() for error handling in the
    request_header_filter and response_header_filter methods. This would allow for more
    graceful error propagation and handling.

    bongonet-core/src/protocols/http/bridge/grpc_web.rs [68-74]

    -req.insert_header(CONTENT_TYPE, ct).expect("insert header");
    +req.insert_header(CONTENT_TYPE, ct).map_err(|e| Error::new(ErrorType::InternalError, e))?;
     // ...
    -req.insert_header("te", "trailers").expect("insert header");
    +req.insert_header("te", "trailers").map_err(|e| Error::new(ErrorType::InternalError, e))?;
    Suggestion importance[1-10]: 8

    Why: Using the ? operator for error handling improves the robustness of the code by allowing for graceful error propagation. This change enhances error handling practices, making the code more maintainable and less prone to crashes.

    8
    Implement error handling for gRPC-Web response trailer filtering

    Consider implementing error handling for the response_trailer_filter method to
    handle cases where the trailers conversion might fail.

    bongonet-core/src/modules/http/grpc_web.rs [62-70]

     fn response_trailer_filter(
         &mut self,
         trailers: &mut Option<Box<HeaderMap>>,
     ) -> Result<Option<Bytes>> {
         if let Some(trailers) = trailers {
    -        return self.0.response_trailer_filter(trailers);
    +        self.0.response_trailer_filter(trailers).map_err(|e| {
    +            Error::new(
    +                ErrorType::InternalError,
    +                format!("Failed to filter gRPC-Web response trailers: {}", e),
    +            )
    +        })
    +    } else {
    +        Ok(None)
         }
    -    Ok(None)
     }
    • Apply this suggestion
    Suggestion importance[1-10]: 8

    Why: Implementing error handling for the response_trailer_filter method is a significant improvement, as it ensures robustness by handling potential errors during trailer conversion, which is crucial for maintaining reliable software.

    8
    Best practice
    Define a constant for the CRLF separator to improve code readability and maintainability

    Consider using a constant for the CRLF separator ("\r\n") to improve code
    readability and maintainability. You can define it at the top of the file and use it
    throughout the code.

    bongonet-core/src/protocols/http/bridge/grpc_web.rs [169]

    -trailers.put_slice(b"\r\n");
    +const CRLF: &[u8] = b"\r\n";
    +// ...
    +trailers.put_slice(CRLF);
    Suggestion importance[1-10]: 7

    Why: Defining a constant for the CRLF separator enhances code readability and maintainability by reducing repetition and potential errors. This is a good practice, especially when the separator is used multiple times in the code.

    7
    Improve debug logging accuracy for END_STREAM on HEADERS

    Consider using a constant or configuration value for the debug log message about
    sending END_STREAM on HEADERS, instead of hardcoding the value.

    bongonet-proxy/src/proxy_h2.rs [141-143]

     // send END_STREAM on HEADERS
     let send_header_eos = send_end_stream && body_empty;
    -debug!("send END_STREAM on HEADERS: {send_end_stream}");
    +debug!("send END_STREAM on HEADERS: {}", send_header_eos);
    • Apply this suggestion
    Suggestion importance[1-10]: 4

    Why: The suggestion to correct the debug log message improves logging accuracy, which is beneficial for debugging. However, it is a minor enhancement and does not impact the core functionality.

    4
    Enhancement
    Simplify temporary object removal using the entry API

    In the finish method of MemMissHandler, consider using entry API to simplify the
    removal of the temporary object. This can make the code more concise and potentially
    more efficient.

    bongonet-cache/src/memory.rs [256-259]

    -self.temp
    -    .write()
    -    .get_mut(&self.key)
    -    .and_then(|map| map.remove(&self.temp_id.into()));
    +self.temp.write().entry(self.key.clone()).and_modify(|map| {
    +    map.remove(&self.temp_id.into());
    +});
    • Apply this suggestion
    Suggestion importance[1-10]: 7

    Why: Using the entry API can make the code more concise and potentially more efficient by reducing the number of lookups needed to remove an item from the map.

    7
    Use HeaderMap::drain() to simplify header encoding and potentially improve performance

    Consider using HeaderMap::drain() instead of iterating over the headers and manually
    encoding them. This can simplify the code and potentially improve performance.

    bongonet-core/src/protocols/http/bridge/grpc_web.rs [159-170]

    -for (key, value) in resp_trailers.iter() {
    -    // encode header
    -    trailers.put_slice(key.as_ref());
    -    trailers.put_slice(b":");
    -    // encode value
    -    trailers.put_slice(value.as_ref());
    -    // encode header separator
    -    trailers.put_slice(b"\r\n");
    +for (key, value) in resp_trailers.drain() {
    +    trailers.extend_from_slice(key.as_ref());
    +    trailers.extend_from_slice(b": ");
    +    trailers.extend_from_slice(value.as_ref());
    +    trailers.extend_from_slice(CRLF);
     }
    • Apply this suggestion
    Suggestion importance[1-10]: 6

    Why: Using HeaderMap::drain() can simplify the code by removing the need for manual iteration and encoding, potentially improving performance. However, the performance gain might be marginal, so the impact is moderate.

    6
    Improve readability of nested and_then calls in lookup_streaming_write

    In the lookup_streaming_write method, consider using and_then chaining instead of
    nested and_then calls for better readability and to avoid increasing indentation
    levels.

    bongonet-cache/src/memory.rs [332-338]

    -hit_from_temp_obj(
    -    self.temp
    -        .read()
    -        .get(&hash)
    -        .and_then(|map| map.get(&write_tag.into()))
    -        .expect("must have partial write in progress"),
    -)
    +self.temp
    +    .read()
    +    .get(&hash)
    +    .and_then(|map| map.get(&write_tag.into()))
    +    .map(hit_from_temp_obj)
    +    .expect("must have partial write in progress")
    • Apply this suggestion
    Suggestion importance[1-10]: 6

    Why: The suggestion improves code readability by reducing indentation levels, making it easier to follow the logic. However, it does not significantly change the functionality or performance.

    6
    Simplify the temp field type by removing potentially unnecessary Arc wrapper

    Consider using a RwLock<HashMap<String, HashMap<u64, TempObject>>> instead of
    Arc<RwLock<HashMap<String, HashMap<u64, TempObject>>>> for temp. The Arc wrapper
    might be unnecessary if MemCache is already wrapped in an Arc when used.

    bongonet-cache/src/memory.rs [72]

    -pub(crate) temp: Arc<RwLock<HashMap<String, HashMap<u64, TempObject>>>>,
    +pub(crate) temp: RwLock<HashMap<String, HashMap<u64, TempObject>>>,
    • Apply this suggestion
    Suggestion importance[1-10]: 5

    Why: Removing the Arc wrapper could simplify the code if MemCache is already wrapped in an Arc elsewhere. However, without full context, this change might affect thread safety or shared ownership, so it should be considered carefully.

    5
    Improve variable naming for clarity in the response trailer filtering process

    Consider using a more descriptive name for the encoded variable, such as
    trailer_buffer, to better reflect its purpose in storing the encoded trailers.

    bongonet-core/src/modules/http/mod.rs [251-257]

    -let mut encoded = None;
    +let mut trailer_buffer = None;
     for filter in self.module_ctx.iter_mut() {
         if let Some(buf) = filter.response_trailer_filter(trailers)? {
    -        encoded = Some(buf);
    +        trailer_buffer = Some(buf);
         }
     }
    -Ok(encoded)
    +Ok(trailer_buffer)
    • Apply this suggestion
    Suggestion importance[1-10]: 5

    Why: The suggestion to rename the variable from encoded to trailer_buffer enhances code readability by providing a more descriptive name, which helps in understanding the code's purpose. However, it does not address any critical issues.

    5
    Maintainability
    Add a detailed comment explaining the trailer-to-body conversion process and its limitations

    Consider adding a comment explaining why we're writing the trailers into the body
    and the potential implications of this approach.

    bongonet-proxy/src/lib.rs [409-419]

     if let Some(buf) = self
         .downstream_modules_ctx
         .response_trailer_filter(trailers)?
     {
    -    // Write the trailers into the body if the filter
    -    // returns a buffer.
    -    //
    -    // Note, this will not work if end of stream has already
    -    // been seen or we've written content-length bytes.
    +    // Write the trailers into the body if the filter returns a buffer.
    +    // This approach allows us to include trailer information even when
    +    // the underlying protocol doesn't support separate trailers.
    +    // However, this has limitations:
    +    // 1. It won't work if the end of stream has already been seen.
    +    // 2. It may cause issues if we've already written the number of bytes
    +    //    specified in the Content-Length header.
    +    // 3. It may not be compatible with all client implementations.
         *task = HttpTask::Body(Some(buf), true);
     }
    • Apply this suggestion
    Suggestion importance[1-10]: 7

    Why: Adding a detailed comment improves code maintainability by explaining the rationale and limitations of writing trailers into the body. This is valuable for future developers who might work on this code.

    7

    💡 Need additional feedback ? start a PR chat

    Signed-off-by: KhulnaSoft bot <[email protected]>
    @khulnasoft-bot khulnasoft-bot merged commit 120283d into main Sep 28, 2024
    7 checks passed
    @khulnasoft-bot khulnasoft-bot deleted the no-clippy-msrv branch September 28, 2024 08:59
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Projects
    None yet
    Development

    Successfully merging this pull request may close these issues.

    1 participant