Skip to content

Conversation

JosePineiro
Copy link

This PR updates the _getEtag implementation in AsyncWebServerRequest to improve how ETags are generated.

Previously, the method relied on a 4-byte trailer buffer passed as a parameter. This has been replaced with a more robust approach: the function now reads the CRC directly from the last 8 bytes of the gzip file. This ensures that the ETag is derived from the actual file contents rather than depending on an external buffer.

Key changes:

_getEtag now accepts a File handle instead of a trailer array.

The method seeks to the gzip footer (size - 8) and extracts the CRC.

Returns bool to indicate success/failure.

ETag generation logic remains the same, ensuring backward compatibility for clients relying on ETags.

This change improves correctness, reduces external dependencies, and makes ETag generation more consistent with the gzip specification.

This PR updates the _getEtag implementation in AsyncWebServerRequest to improve how ETags are generated.

Previously, the method relied on a 4-byte trailer buffer passed as a parameter. This has been replaced with a more robust approach: the function now reads the CRC directly from the last 8 bytes of the gzip file. This ensures that the ETag is derived from the actual file contents rather than depending on an external buffer.

Key changes:

_getEtag now accepts a File handle instead of a trailer array.

The method seeks to the gzip footer (size - 8) and extracts the CRC.

Returns bool to indicate success/failure.

ETag generation logic remains the same, ensuring backward compatibility for clients relying on ETags.

This change improves correctness, reduces external dependencies, and makes ETag generation more consistent with the gzip specification.
@JosePineiro
Copy link
Author

This is the same change as in PR #245.
The conflict has been fixed.

Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR refactors the ETag generation mechanism for gzip-compressed files to improve correctness and robustness. Instead of relying on external trailer buffers, the system now reads the CRC32 checksum directly from the gzip file footer.

  • Updated _getEtag method to accept a File handle and return success/failure status
  • Modified AsyncFileResponse constructor to use the new ETag generation approach
  • Streamlined file opening logic by removing unnecessary else block

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
src/ESPAsyncWebServer.h Updated _getEtag method signature to accept File handle and return bool
src/AsyncWebServerRequest.cpp Implemented new ETag generation logic that reads CRC from gzip footer
src/WebResponses.cpp Updated AsyncFileResponse constructor to use new ETag method and simplified file opening logic

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@mathieucarbou mathieucarbou merged commit 879d57c into ESP32Async:main Aug 21, 2025
33 checks passed
@JosePineiro JosePineiro deleted the refactor/etag-from-gzip-crc32 branch August 21, 2025 15:44
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.

2 participants