int HTTPConnection::request(const std::string &path, const BytesRange &range) { queryOk = false; /* Set new path for this query */ params.setPath(path); msg_Dbg(p_object, "Retrieving %s @%zu", params.getUrl().c_str(), range.isValid() ? range.getStartByte() : 0); if(!connected() && ( params.getHostname().empty() || !connect() )) return VLC_EGENERIC; bytesRange = range; if(range.isValid() && range.getEndByte() > 0) contentLength = range.getEndByte() - range.getStartByte() + 1; std::string header = buildRequestHeader(path); if(connectionClose) header.append("Connection: close\r\n"); header.append("\r\n"); if(!send( header )) { socket->disconnect(); if(!connectionClose) { /* server closed connection pipeline after last req. need new */ connectionClose = true; return request(path, range); } return VLC_EGENERIC; } int i_ret = parseReply(); if(i_ret == VLC_SUCCESS) { queryOk = true; } else if(i_ret == VLC_EGENERIC) { socket->disconnect(); if(!connectionClose) { connectionClose = true; return request(path, range); } } return i_ret; }
enum RequestStatus HTTPConnection::request(const std::string &path, const BytesRange &range) { queryOk = false; chunked = false; chunked_eof = false; chunkLength = 0; /* Set new path for this query */ params.setPath(path); locationparams = ConnectionParams(); msg_Dbg(p_object, "Retrieving %s @%zu", params.getUrl().c_str(), range.isValid() ? range.getStartByte() : 0); std::string querypath; if(!proxyparams.getHostname().empty()) { msg_Dbg(p_object, "Using proxy %s", proxyparams.getUrl().c_str()); querypath = params.getUrl(); } else querypath = path; if(!connected() && ( params.getHostname().empty() || !connect() )) return RequestStatus::GenericError; bytesRange = range; if(range.isValid() && range.getEndByte() > 0) contentLength = range.getEndByte() - range.getStartByte() + 1; std::string header = buildRequestHeader(querypath); if(connectionClose) header.append("Connection: close\r\n"); header.append("\r\n"); if(!send( header )) { transport->disconnect(); if(!connectionClose) { /* server closed connection pipeline after last req. need new */ connectionClose = true; return request(path, range); } return RequestStatus::GenericError; } enum RequestStatus status = parseReply(); if(status == RequestStatus::Success) { queryOk = true; } else if(status == RequestStatus::Redirection) { transport->disconnect(); } else if(status == RequestStatus::GenericError) { transport->disconnect(); if(!connectionClose) { connectionClose = true; return request(path, range); } } return status; }