Skip to content

Commit c67764d

Browse files
committed
HttpRequest subclass of BaseStream
1 parent abc42d5 commit c67764d

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ GeneratedSoundStream<int16_t> sound(sineWave);
1717
TimedStream timed(sound);
1818
WiFiClient client;
1919
HttpRequest http(client);
20-
StreamCopy copier(client, sound); // copy kit to kit
20+
StreamCopy copier(http, sound); // copy kit to kit
2121

2222
void startWiFi() {
2323
WiFi.mode(WIFI_STA);
@@ -48,6 +48,7 @@ void setup(void) {
4848

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

src/AudioTools/CoreAudio/AudioHttp/HttpRequest.h

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ namespace audio_tools {
2323
* @copyright GPLv3
2424
*/
2525

26-
class HttpRequest {
26+
class HttpRequest : public BaseStream {
2727
public:
2828
friend class URLStream;
2929

@@ -51,20 +51,25 @@ class HttpRequest {
5151
return client_ptr == nullptr ? false : client_ptr->connected();
5252
}
5353

54-
virtual int available() {
54+
virtual int available() override {
5555
if (reply_header.isChunked()) {
5656
return chunk_reader.available();
5757
}
5858
return client_ptr != nullptr ? client_ptr->available() : 0;
5959
}
6060

61-
virtual void stop() {
61+
/// same as end()
62+
void end() override {
6263
if (connected()) {
6364
LOGI("stop");
6465
client_ptr->stop();
6566
}
6667
}
6768

69+
virtual void stop() override {
70+
end();
71+
}
72+
6873
/// http post
6974
virtual int post(Url &url, const char *mime, const char *data, int len = -1) {
7075
LOGI("post %s", url.url());
@@ -122,7 +127,11 @@ class HttpRequest {
122127
}
123128
}
124129

125-
size_t readBytesUntil(char terminator, char *buffer, size_t length) {
130+
size_t readBytes(uint8_t *str, size_t len) override {
131+
return read(str, len);
132+
}
133+
134+
size_t readBytesUntil(char terminator, char *buffer, size_t length) {
126135
return client_ptr->readBytesUntil(terminator, buffer, length);
127136
}
128137

@@ -268,7 +277,7 @@ class HttpRequest {
268277

269278
/// Write data to the client: can be used to post data after calling
270279
/// processBegin
271-
virtual size_t write(uint8_t *data, size_t len) {
280+
size_t write(const uint8_t *data, size_t len) override {
272281
size_t result = 0;
273282
if (isChunked()) {
274283
client_ptr->println(len);

0 commit comments

Comments
 (0)