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

Add basic auth feature and SSL feature. #410

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion src/AudioFileSourceHTTPStream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,23 @@ AudioFileSourceHTTPStream::AudioFileSourceHTTPStream(const char *url)
open(url);
}

void AudioFileSourceHTTPStream::setClient(WiFiClient *client)
{
this->client = client;
}

void AudioFileSourceHTTPStream::setAuthorization(const char *user, const char *password)
{
http.setAuthorization(user, password);
}

bool AudioFileSourceHTTPStream::open(const char *url)
{
pos = 0;
http.begin(client, url);
if (client == nullptr) {
client = new WiFiClient();
}
http.begin(*client, url);
http.setReuse(true);
#ifndef ESP32
http.setFollowRedirects(HTTPC_FORCE_FOLLOW_REDIRECTS);
Expand Down
6 changes: 4 additions & 2 deletions src/AudioFileSourceHTTPStream.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,18 +48,20 @@ class AudioFileSourceHTTPStream : public AudioFileSource
virtual uint32_t getPos() override;
bool SetReconnect(int tries, int delayms) { reconnectTries = tries; reconnectDelayMs = delayms; return true; }
void useHTTP10 () { http.useHTTP10(true); }
void setAuthorization(const char *user, const char *password);
void setClient(WiFiClient *client);

enum { STATUS_HTTPFAIL=2, STATUS_DISCONNECTED, STATUS_RECONNECTING, STATUS_RECONNECTED, STATUS_NODATA };

private:
virtual uint32_t readInternal(void *data, uint32_t len, bool nonBlock);
WiFiClient client;
WiFiClient *client = nullptr;
HTTPClient http;
int pos;
int size;
int reconnectTries;
int reconnectDelayMs;
char saveURL[128];
char saveURL[1024];
harajune marked this conversation as resolved.
Show resolved Hide resolved
};


Expand Down
2 changes: 1 addition & 1 deletion src/AudioFileSourceICYStream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ bool AudioFileSourceICYStream::open(const char *url)
{
static const char *hdr[] = { "icy-metaint", "icy-name", "icy-genre", "icy-br" };
pos = 0;
http.begin(client, url);
http.begin(*client, url);
http.addHeader("Icy-MetaData", "1");
http.collectHeaders( hdr, 4 );
http.setReuse(true);
Expand Down