public void RespondSuccess(string contentType, int contentLength) { string response = "HTTP/1.1 200 OK" + Environment.NewLine + "Content-Type: " + contentType + Environment.NewLine + "Content-Length: " + contentLength + Environment.NewLine + "Connection: close"; HttpHelper.WriteHttpHeader(response, _stream); }
public void Respond() { HttpHelper.WriteHttpHeader("HTTP/1.1 400 Bad Request", _stream); // limit what we log. Headers can be up to 16K in size string header = _header.Length > 255 ? _header.Substring(0, 255) + "..." : _header; _logger.Warning(this.GetType(), "Bad request: '{0}'", header); }
public void Respond() { HttpHelper.WriteHttpHeader("HTTP/1.1 400 Bad Request", _stream); // limit what we log. Headers can be up to 16K in size int length = 1024 * 16; // 16KB buffer more than enough for http header string header = _header.Length > length?_header.Substring(0, length) + "..." : _header; _logger.Warning("", this.GetType(), "Bad request: '{0}'", header); }
public void RespondSuccess(int contentLength) { string nErrorString = "HTTP/1.1 204 No Content"; string response = nErrorString + Environment.NewLine + "Content-Type: text/html" + Environment.NewLine + "Content-Length: " + contentLength + Environment.NewLine + "Connection: close"; HttpHelper.WriteHttpHeader(response, _stream); }
//No resume support (yet) public void RespondBinaryHeader(long iFileSize, string sFileName, string sFilePath, string sMime, bool bPartial = false, long lRangeFrom = 0, long lRangeTo = 0, DateTime dateFileModified = default(DateTime)) { string sResponse = "HTTP/1.1 200 OK"; string sRange = "Accept-Ranges: bytes"; long lContentLength = iFileSize; if (bPartial) { sResponse = "HTTP/1.1 206 Partial Content"; if (lRangeTo == 0) //Just a precaution { lRangeTo = 1; } sRange = String.Format("Content-Range: bytes {0}-{1}/{2}", lRangeFrom.ToString(), (lRangeTo - 1).ToString(), iFileSize.ToString()); lContentLength = (lRangeTo - lRangeFrom); } if (!sHTTPHeader.Contains("CAST-DEVICE-CAPABILITIES")) { string response = sResponse + Environment.NewLine + "Pragma: no-cache" + Environment.NewLine + "Server: MOTRd/1.1" + Environment.NewLine + "ETag: " + GetBase64EncodedSHA1Hash(sFilePath) + Environment.NewLine + "Expires: 0" + Environment.NewLine + "Connection: close" + Environment.NewLine + "Accept-Encoding: identity" + Environment.NewLine + "Access-Control-Allow-Origin: *" + Environment.NewLine + //Needed for Chromecast: CORS headers: https://stackoverflow.com/questions/22207867/how-to-enable-cors-for-streaming-on-chromecast-using-media-player-library "Cache-Control: no-cache, no-store, must-revalidate" + Environment.NewLine + "Content-Length: " + lContentLength + Environment.NewLine + sRange + Environment.NewLine + "Content-Description: File Transfer" + Environment.NewLine + "Content-Type: " + sMime + Environment.NewLine + "Content-Disposition: attachment; filename=\"" + sFileName + "\"" + Environment.NewLine + "Content-Transfer-Encoding: binary" + Environment.NewLine; _logger.Debug(this.GetType(), "Sending header: " + response); HttpHelper.WriteHttpHeader(response, _stream); } else //Here is chromecast header { string response = sResponse + Environment.NewLine + sRange + Environment.NewLine + "Last-Modified: " + dateFileModified.ToString("r") + Environment.NewLine + "Date: " + DateTime.UtcNow.ToString("r") + Environment.NewLine + "Server: MOTRd/1.1" + Environment.NewLine + "Content-Length: " + lContentLength + Environment.NewLine + "Content-Type: " + sMime + Environment.NewLine + "Connection: close" + Environment.NewLine; _logger.Debug(this.GetType(), "Sending CC-header: " + response); HttpHelper.WriteHttpHeader(response, _stream); } }
public void RespondSuccess(string contentType, int contentLength) { string response = "HTTP/1.1 200 OK" + Environment.NewLine + "Cache-Control: no-cache, no-store, must-revalidate" + Environment.NewLine + "Pragma: no-cache" + Environment.NewLine + "Expires: 0" + Environment.NewLine + "Content-Type: " + contentType + "; charset=utf-8" + Environment.NewLine + "Content-Length: " + contentLength + Environment.NewLine; response += "Connection: close"; HttpHelper.WriteHttpHeader(response, _stream); }
public void RespondSuccess(int contentLength) { string response = "HTTP/1.1 200 OK" + Environment.NewLine + "Content-Type: text/html" + Environment.NewLine + "Content-Length: " + contentLength + Environment.NewLine; //Remove all the cookies on demand if (bDeleteSession) { response += "Set-Cookie: SessionID=; expires=Thu, 01 Jan 1970 00:00:00 GMT; path=/;" + Environment.NewLine; response += "Set-Cookie: TempID=; expires=Thu, 01 Jan 1970 00:00:00 GMT; path=/;" + Environment.NewLine; response += "Set-Cookie: ReturnTo=; expires=Thu, 01 Jan 1970 00:00:00 GMT; path=/;" + Environment.NewLine; } response += "Connection: close"; HttpHelper.WriteHttpHeader(response, _stream); }
public void RespondRedirect(string sRedirect, string sReturnToUrl) { // string response = "HTTP/1.1 200 OK" + Environment.NewLine + // "Content-Type: text/html" + Environment.NewLine + // "Content-Length: " + contentLength + Environment.NewLine + // "Connection: close"; string response = "HTTP/1.1 302 Found" + Environment.NewLine + "Location: " + sRedirect + Environment.NewLine; response += "Cache-Control: no-cache, no-store, must-revalidate" + Environment.NewLine + "Pragma: no-cache" + Environment.NewLine + "Expires: 0" + Environment.NewLine; if (sCookie.Length > 0) { //Delete the cookie if requested if (sCookie == "[DELETE]") { sCookie = "; expires=Thu, 01 Jan 1970 00:00:00 GMT"; } } //Do not reset session if we are downloading if (!sRedirect.Contains("/MOTR-download/")) { response += "Set-Cookie: SessionID = " + sCookie + "; HttpOnly; SameSite=strict; path=/;" + Environment.NewLine; } response += "Set-Cookie: TempID = ; expires=Thu, 01 Jan 1970 00:00:00 GMT; path=/;" + Environment.NewLine; if (sReturnToUrl.Length > 0) { response += "Set-Cookie: ReturnTo = " + sReturnToUrl + Environment.NewLine; } response += "Connection: close"; HttpHelper.WriteHttpHeader(response, _stream); }
public void RespondNotFoundFailure(string file) { HttpHelper.WriteHttpHeader("HTTP/1.1 404 Not Found", _stream); _logger.Information("", this.GetType(), "File not found: {0}", file); }
public void RespondMimeTypeFailure(string file) { HttpHelper.WriteHttpHeader("415 Unsupported Media Type", _stream); _logger.Warning("", this.GetType(), "File extension not found MimeTypes.config: {0}", file); }