Skip to content

Commit 444e896

Browse files
committed
HttpRequest chunked corrections
1 parent ef3a8a0 commit 444e896

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

examples/examples-communication/http-client/streams-http_post/streams-http_post.ino

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
const char *ssid = "your SSID";
1313
const char *password = "your PASSWORD";
14+
const char *url_str = "http://192.168.1.44:9999";
1415
AudioInfo info(44100, 2, 16);
1516
SineWaveGenerator<int16_t> sineWave(32000);
1617
GeneratedSoundStream<int16_t> sound(sineWave);
@@ -47,8 +48,8 @@ void setup(void) {
4748
timed.begin();
4849

4950
// start post
50-
Url url("http://192.168.1.35:8000");
51-
// http.header().put(TRANSFER_ENCODING, CHUNKED); // uncomment if chunked
51+
Url url(url_str);
52+
http.header().put(TRANSFER_ENCODING, CHUNKED); // uncomment if chunked
5253
if (!http.processBegin(POST, url, "audio/pcm")){
5354
Serial.println("post failed");
5455
stop();

src/AudioTools/CoreAudio/AudioHttp/HttpRequest.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,12 +132,14 @@ class HttpRequest : public BaseStream {
132132
}
133133

134134
size_t readBytesUntil(char terminator, char *buffer, size_t length) {
135+
TRACED();
135136
return client_ptr->readBytesUntil(terminator, buffer, length);
136137
}
137138

138139
// read the reply data up to the next new line. For Chunked data we provide
139140
// the full chunk!
140141
virtual int readln(uint8_t *str, int len, bool incl_nl = true) {
142+
TRACED();
141143
if (reply_header.isChunked()) {
142144
return chunk_reader.readln(*client_ptr, str, len);
143145
} else {
@@ -278,13 +280,14 @@ class HttpRequest : public BaseStream {
278280
/// Write data to the client: can be used to post data after calling
279281
/// processBegin
280282
size_t write(const uint8_t *data, size_t len) override {
283+
TRACED();
281284
size_t result = 0;
282285
if (isChunked()) {
283-
client_ptr->println(len);
284286
if (len > 0) {
287+
client_ptr->println(len, HEX);
285288
result = client_ptr->write(data, len);
289+
client_ptr->println();
286290
}
287-
client_ptr->println();
288291
} else {
289292
result = client_ptr->write(data, len);
290293
}
@@ -293,6 +296,7 @@ class HttpRequest : public BaseStream {
293296

294297
/// Ends the http request processing and returns the status code
295298
virtual int processEnd() {
299+
TRACED();
296300
// if sending is chunked we terminate with an empty chunk
297301
if (isChunked()) {
298302
write(nullptr, 0);
@@ -342,6 +346,7 @@ class HttpRequest : public BaseStream {
342346

343347
// opens a connection to the indicated host
344348
virtual int connect(const char *ip, uint16_t port, int32_t timeout) {
349+
TRACED();
345350
client_ptr->setTimeout(timeout / 1000); // client timeout is in seconds!
346351
request_header.setTimeout(timeout);
347352
reply_header.setTimeout(timeout);

0 commit comments

Comments
 (0)