namespace android {
+static const char *kUserAgent = "stagefright-http";
+
// Given a connected HTTPStream, determine if the given path redirects
// somewhere else, if so, disconnect the stream, update host path and port
// accordingly and return true, otherwise return false and leave the stream
request.append("HEAD ");
request.append(path->c_str());
request.append(" HTTP/1.1\r\n");
+ request.append("User-Agent: ");
+ request.append(kUserAgent);
+ request.append("\r\n");
request.append("Host: ");
request.append(host->c_str());
request.append("\r\n\r\n");
CHECK(end > start && (*end == '\0'));
*port = (tmp >= 0 && tmp < 65536) ? (int)tmp : 80;
+
+ host->erase(colonPos, host->size() - colonPos);
} else {
*port = 80;
}
mPath(NULL),
mBuffer(malloc(kBufferSize)),
mBufferLength(0),
- mBufferOffset(0) {
+ mBufferOffset(0),
+ mFirstRequest(true) {
CHECK(!strncasecmp("http://", uri, 7));
string host;
host = string(host, 0, colon - host.c_str());
}
- LOGI("Connecting to host '%s', port %d, path '%s'",
- host.c_str(), port, path.c_str());
-
do {
+ LOGI("Connecting to host '%s', port %d, path '%s'",
+ host.c_str(), port, path.c_str());
+
mInitCheck = mHttp->connect(host.c_str(), port);
if (mInitCheck != OK) {
mPath(NULL),
mBuffer(malloc(kBufferSize)),
mBufferLength(0),
- mBufferOffset(0) {
+ mBufferOffset(0),
+ mFirstRequest(true) {
string host = _host;
string path = _path;
}
ssize_t HTTPDataSource::sendRangeRequest(size_t offset) {
+ char agent[128];
+ sprintf(agent, "User-Agent: %s\r\n", kUserAgent);
+
char host[128];
sprintf(host, "Host: %s\r\n", mHost);
char range[128];
- sprintf(range, "Range: bytes=%d-\r\n\r\n", offset);
+ if (offset > 0) {
+ sprintf(range, "Range: bytes=%d-\r\n\r\n", offset);
+ } else {
+ range[0] = '\0';
+ }
int http_status;
if ((err = mHttp->send("GET ")) != OK
|| (err = mHttp->send(mPath)) != OK
|| (err = mHttp->send(" HTTP/1.1\r\n")) != OK
+ || (err = mHttp->send(agent)) != OK
|| (err = mHttp->send(host)) != OK
|| (err = mHttp->send(range)) != OK
|| (err = mHttp->send("\r\n")) != OK
string value;
if (!mHttp->find_header_value("Content-Length", &value)) {
- return UNKNOWN_ERROR;
+ return kBufferSize;
}
char *end;
}
ssize_t contentLength = 0;
- if (mBufferLength <= 0 || offset != mBufferOffset + mBufferLength) {
- mHttp->disconnect();
+ if (mFirstRequest || offset != mBufferOffset + mBufferLength) {
+ if (!mFirstRequest) {
+ mHttp->disconnect();
+ }
+ mFirstRequest = false;
+
contentLength = sendRangeRequest(offset);
if (contentLength > kBufferSize) {