public void content_type_encoding() { string contentType = HTTP.MimeTypeFromExtension("html"); string encoding = HTTP.CONTENT_ENCODING_UTF8; Assert.AreEqual(HTTP.ContentTypeEncoding(contentType, encoding), "text/html; charset=utf-8"); }
/// <summary> /// Handles the response by create a HTTP response with the text from the request /// in lower case. /// </summary> /// <param name="req">Request.</param> /// <returns>Reponse with lower case text as content.</returns> public IResponse Handle(IRequest req) { string body = req.ContentString; body = body.Remove(0, body.IndexOf('=') + 1); // Create response Response response = new Response(); response.StatusCode = 200; response.ContentType = HTTP.ContentTypeEncoding(HTTP.CONTENT_TYPE_TEXT_PLAIN, "UTF-8"); response.AddHeader(HTTP.CONNECTION, HTTP.CONNECTION_CLOSED); response.AddHeader(HTTP.CONTENT_LANGUAGE, HTTP.CONTENT_LANGUAGE_EN); // Send empty handling protocol if (string.IsNullOrEmpty(body.Trim())) { response.SetContent("Bitte geben Sie einen Text ein"); return(response); } // Send correctly executed protocol response.SetContent(body.ToLower()); return(response); }
/// <summary> /// Initializes the given response for the given file. /// </summary> /// <param name="response">Response.</param> /// <param name="file">File to be sent.</param> /// <returns>Setup response with file data and status codes.</returns> private IResponse CreateResponse(IResponse response, string file) { // Get file extension string ext = Path.GetExtension(file); // Send response file response.StatusCode = 200; response.ContentType = HTTP.ContentTypeEncoding(HTTP.MimeTypeFromExtension(ext), "UTF-8"); response.SetContent(File.ReadAllBytes(file)); return(response); }
/// <summary> /// Handles the response and creates a response object which delivers the standard test plugin /// page. /// </summary> /// <param name="req">Request.</param> /// <returns>Created response.</returns> public IResponse Handle(IRequest req) { Response response = new Response(); response.AddHeader(HTTP.CONNECTION, HTTP.CONNECTION_CLOSED); response.AddHeader(HTTP.CONTENT_LANGUAGE, HTTP.CONTENT_LANGUAGE_EN); response.AddHeader(HTTP.CONTENT_ENCODING, HTTP.CONTENT_ENCODING_UTF8); response.StatusCode = 200; response.ContentType = HTTP.ContentTypeEncoding(HTTP.CONTENT_TYPE_TEXT_HTML, "UTF-8"); response.SetContent("<!DOCTYPE html><html><body><h1>Test Plugin</h1><h3>#+ßöäüabc123</h3></body></html>"); return(response); }