Skip to content

Commit cf5385e

Browse files
committed
add ci gzip et clang
1 parent e469f4b commit cf5385e

9 files changed

Lines changed: 88 additions & 16 deletions

File tree

.github/workflows/lint.yml

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ jobs:
1515
run: sudo apt-get update && sudo apt-get install -y clang-format
1616
- name: Check formatting
1717
run: |
18-
files=$(git ls-files '*.h' '*.cpp' '*.ino')
18+
# Exclude vendored third-party sources from formatting checks.
19+
files=$(git ls-files '*.h' '*.cpp' '*.ino' | grep -v '^src/third_party/' || true)
1920
echo "Checking clang-format on: $files"
2021
diff_found=0
2122
for f in $files; do
@@ -33,7 +34,11 @@ jobs:
3334
run: pip install cpplint
3435
- name: Run cpplint
3536
run: |
36-
cpplint --recursive --extensions=h,cpp src || true
37+
# Keep third_party out of lint noise.
38+
files=$(git ls-files src | grep -E '\\.(h|cpp)$' | grep -v '^src/third_party/' || true)
39+
if [ -n "$files" ]; then
40+
cpplint $files || true
41+
fi
3742
# We don't fail hard yet; adjust policy later
3843
cppcheck:
3944
runs-on: ubuntu-latest
@@ -45,7 +50,7 @@ jobs:
4550
run: |
4651
cppcheck --enable=warning,style,performance --inline-suppr \
4752
--suppress=missingIncludeSystem \
48-
-I src --quiet src || true
53+
-I src --quiet src --exclude=src/third_party || true
4954
version-sync:
5055
runs-on: ubuntu-latest
5156
steps:

.github/workflows/test.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,14 +199,17 @@ jobs:
199199
path: |
200200
~/.platformio/.cache
201201
key: ${{ runner.os }}-pio-${{ hashFiles('platformio.ini') }}
202-
- name: Run native unit tests (UrlParser)
202+
- name: Run native unit tests (UrlParser + gzip)
203203
if: ${{ hashFiles('test/**') != '' }}
204204
run: |
205205
echo "Detected test files:" $(ls test || true)
206-
pio test -e native -f test_urlparser_native -v
206+
pio test -e native -f test_urlparser_native -f test_gzip_decode_native -v
207207
- name: Skip notice (no tests found)
208208
if: ${{ hashFiles('test/**') == '' }}
209209
run: echo "No test directory present in this ref; skipping native tests."
210+
- name: Compile ESP32 (gzip enabled)
211+
run: |
212+
pio run -e compile_test_gzip -v
210213
211214
python-parse-tests:
212215
runs-on: ubuntu-latest

platformio.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,3 +92,4 @@ build_src_filter = -<*> +<UrlParser.cpp> +<GzipDecoder.cpp> +<third_party/miniz/
9292
build_flags =
9393
-I test/test_urlparser_native
9494
-I src
95+
-DASYNC_HTTP_ENABLE_GZIP_DECODE=1

src/AsyncHttpClient.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -696,7 +696,7 @@ void AsyncHttpClient::handleData(RequestContext* context, char* data, size_t len
696696
size_t outLen = 0;
697697
size_t consumed = 0;
698698
GzipDecoder::Result r = context->gzipDecoder.write(reinterpret_cast<const uint8_t*>(wire + offset),
699-
wireLen - offset, &consumed, &outPtr, &outLen, true);
699+
wireLen - offset, &consumed, &outPtr, &outLen, true);
700700
if (outLen > 0) {
701701
if (!emitBodyBytes(reinterpret_cast<const char*>(outPtr), outLen))
702702
return false;

src/AsyncHttpClient.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -179,10 +179,9 @@ class AsyncHttpClient {
179179
RequestContext()
180180
: request(nullptr), response(nullptr), transport(nullptr), headersComplete(false), responseProcessed(false),
181181
expectedContentLength(0), receivedContentLength(0), receivedBodyLength(0), chunked(false),
182-
chunkedComplete(false),
183-
currentChunkRemaining(0), awaitingFinalChunkTerminator(false), id(0), trailerLineCount(0),
184-
redirectCount(0), notifiedEndCallback(false), connectStartMs(0), connectTimeoutMs(0), headersSent(false),
185-
streamingBodyInProgress(false), requestKeepAlive(false), serverRequestedClose(false),
182+
chunkedComplete(false), currentChunkRemaining(0), awaitingFinalChunkTerminator(false), id(0),
183+
trailerLineCount(0), redirectCount(0), notifiedEndCallback(false), connectStartMs(0), connectTimeoutMs(0),
184+
headersSent(false), streamingBodyInProgress(false), requestKeepAlive(false), serverRequestedClose(false),
186185
usingPooledConnection(false)
187186
#if ASYNC_HTTP_ENABLE_GZIP_DECODE
188187
,

src/GzipDecoder.cpp

Lines changed: 61 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,60 @@
11
#include "GzipDecoder.h"
22

3+
#if !ASYNC_HTTP_ENABLE_GZIP_DECODE
4+
5+
#include <string.h>
6+
7+
GzipDecoder::GzipDecoder()
8+
: _state(State::kError), _headerStage(HeaderStage::kFixed10), _error("Gzip decode disabled"), _fixedLen(0),
9+
_flags(0), _extraLenRead(0), _extraRemaining(0), _needName(false), _needComment(false), _needHcrc(false),
10+
_trailerLen(0), _dict(nullptr), _dictOfs(0), _decomp(nullptr) {
11+
memset(_fixed, 0, sizeof(_fixed));
12+
memset(_extraLenBytes, 0, sizeof(_extraLenBytes));
13+
memset(_trailer, 0, sizeof(_trailer));
14+
}
15+
16+
GzipDecoder::~GzipDecoder() {}
17+
18+
void GzipDecoder::reset() {}
19+
20+
bool GzipDecoder::begin() {
21+
return false;
22+
}
23+
24+
GzipDecoder::Result GzipDecoder::write(const uint8_t* in, size_t inLen, size_t* inConsumed, const uint8_t** outPtr,
25+
size_t* outLen, bool hasMoreInput) {
26+
(void)in;
27+
(void)inLen;
28+
(void)hasMoreInput;
29+
if (inConsumed)
30+
*inConsumed = 0;
31+
if (outPtr)
32+
*outPtr = nullptr;
33+
if (outLen)
34+
*outLen = 0;
35+
_error = "Gzip decode disabled (build with -DASYNC_HTTP_ENABLE_GZIP_DECODE=1)";
36+
return Result::kError;
37+
}
38+
39+
GzipDecoder::Result GzipDecoder::finish(const uint8_t** outPtr, size_t* outLen) {
40+
if (outPtr)
41+
*outPtr = nullptr;
42+
if (outLen)
43+
*outLen = 0;
44+
_error = "Gzip decode disabled (build with -DASYNC_HTTP_ENABLE_GZIP_DECODE=1)";
45+
return Result::kError;
46+
}
47+
48+
bool GzipDecoder::isDone() const {
49+
return false;
50+
}
51+
52+
const char* GzipDecoder::lastError() const {
53+
return _error ? _error : "";
54+
}
55+
56+
#else
57+
358
#include <stdlib.h>
459
#include <string.h>
560

@@ -18,9 +73,10 @@ static constexpr uint8_t kGzipFlagExtra = 0x04;
1873
static constexpr uint8_t kGzipFlagName = 0x08;
1974
static constexpr uint8_t kGzipFlagComment = 0x10;
2075

21-
GzipDecoder::GzipDecoder() : _state(State::kHeader), _headerStage(HeaderStage::kFixed10), _error(nullptr), _fixedLen(0),
22-
_flags(0), _extraLenRead(0), _extraRemaining(0), _needName(false), _needComment(false),
23-
_needHcrc(false), _trailerLen(0), _dict(nullptr), _dictOfs(0), _decomp(nullptr) {
76+
GzipDecoder::GzipDecoder()
77+
: _state(State::kHeader), _headerStage(HeaderStage::kFixed10), _error(nullptr), _fixedLen(0), _flags(0),
78+
_extraLenRead(0), _extraRemaining(0), _needName(false), _needComment(false), _needHcrc(false), _trailerLen(0),
79+
_dict(nullptr), _dictOfs(0), _decomp(nullptr) {
2480
memset(_fixed, 0, sizeof(_fixed));
2581
memset(_extraLenBytes, 0, sizeof(_extraLenBytes));
2682
memset(_trailer, 0, sizeof(_trailer));
@@ -352,3 +408,5 @@ GzipDecoder::Result GzipDecoder::finish(const uint8_t** outPtr, size_t* outLen)
352408

353409
return r;
354410
}
411+
412+
#endif // ASYNC_HTTP_ENABLE_GZIP_DECODE

src/GzipDecoder.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,4 +78,3 @@ class GzipDecoder {
7878
};
7979

8080
#endif // GZIP_DECODER_H
81-

src/third_party/miniz/miniz_tinfl.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,12 @@
2424
*
2525
**************************************************************************/
2626

27+
#ifndef ASYNC_HTTP_ENABLE_GZIP_DECODE
28+
#define ASYNC_HTTP_ENABLE_GZIP_DECODE 0
29+
#endif
30+
31+
#if ASYNC_HTTP_ENABLE_GZIP_DECODE
32+
2733
#include "miniz.h"
2834

2935
#ifndef MINIZ_NO_INFLATE_APIS
@@ -768,3 +774,5 @@ extern "C"
768774
#endif
769775

770776
#endif /*#ifndef MINIZ_NO_INFLATE_APIS*/
777+
778+
#endif // ASYNC_HTTP_ENABLE_GZIP_DECODE

test/test_gzip_decode_native/test_main.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,7 @@ static std::string decodeGzipInChunks(const std::vector<uint8_t>& gz, size_t chu
2626
const uint8_t* outPtr = nullptr;
2727
size_t outLen = 0;
2828
size_t consumed = 0;
29-
GzipDecoder::Result r =
30-
dec.write(gz.data() + offset + inner, n - inner, &consumed, &outPtr, &outLen, true);
29+
GzipDecoder::Result r = dec.write(gz.data() + offset + inner, n - inner, &consumed, &outPtr, &outLen, true);
3130
if (outLen > 0) {
3231
out.append(reinterpret_cast<const char*>(outPtr), outLen);
3332
}

0 commit comments

Comments
 (0)