Add index.html
This commit is contained in:
@ -3,61 +3,46 @@
|
||||
|
||||
#include "http/http.h"
|
||||
|
||||
void http_index(http_worker_t *worker, FILE *stream)
|
||||
static void http_write_response(
|
||||
FILE *stream,
|
||||
const char *status,
|
||||
const char *content_type,
|
||||
const char *body,
|
||||
unsigned content_length)
|
||||
{
|
||||
fprintf(stream, "HTTP/1.1 200 OK\r\n");
|
||||
fprintf(stream, "Content-Type: text/plain\r\n");
|
||||
if (content_length == 0 && body)
|
||||
content_length = strlen(body);
|
||||
|
||||
fprintf(stream, "HTTP/1.1 %s\r\n", status ? status : "200 OK");
|
||||
fprintf(stream, "Content-Type: %s\r\n", content_type ? content_type : "text/plain");
|
||||
if (content_length > 0)
|
||||
fprintf(stream, "Content-Type: %d\r\n", content_length);
|
||||
fprintf(stream, "\r\n");
|
||||
fprintf(stream, "Text.\r\n");
|
||||
fflush(stream);
|
||||
if (body) {
|
||||
fwrite(body, 1, content_length, stream);
|
||||
}
|
||||
}
|
||||
|
||||
void http_custom_header(FILE *stream, const char *status)
|
||||
void http_content(http_worker_t *worker, FILE *stream)
|
||||
{
|
||||
fprintf(stream, "HTTP/1.1 %s\r\n", status);
|
||||
fprintf(stream, "Content-Type: text/plain\r\n");
|
||||
fprintf(stream, "\r\n");
|
||||
if (worker->current_method) {
|
||||
http_write_response(stream,
|
||||
NULL,
|
||||
worker->current_method->content_type,
|
||||
worker->current_method->content_body,
|
||||
worker->current_method->content_length
|
||||
);
|
||||
} else {
|
||||
http_write_response(stream, NULL, NULL, "No data", 0);
|
||||
}
|
||||
}
|
||||
|
||||
void http_404_header(FILE *stream)
|
||||
void http_404(FILE *stream, const char *data)
|
||||
{
|
||||
http_custom_header(stream, "404 Not Found");
|
||||
fprintf(stream, "HTTP/1.1 404 Not Found\r\n");
|
||||
fprintf(stream, "Content-Type: text/plain\r\n");
|
||||
fprintf(stream, "\r\n");
|
||||
http_write_response(stream, "404 Not Found", NULL, data ? data : "Nothing here.\n", 0);
|
||||
}
|
||||
|
||||
void http_500_header(FILE *stream)
|
||||
void http_500(FILE *stream, const char *data)
|
||||
{
|
||||
http_custom_header(stream, "500 Server Error");
|
||||
}
|
||||
|
||||
void http_404(http_worker_t *worker, FILE *stream)
|
||||
{
|
||||
http_404_header(stream);
|
||||
fprintf(stream, "Nothing here?\r\n");
|
||||
}
|
||||
|
||||
void http_video_html(http_worker_t *worker, FILE *stream)
|
||||
{
|
||||
extern unsigned char html_video_html[];
|
||||
extern unsigned int html_video_html_len;
|
||||
|
||||
fprintf(stream, "HTTP/1.1 200 OK\r\n");
|
||||
fprintf(stream, "Content-Type: text/html;charset=UTF-8\r\n");
|
||||
fprintf(stream, "\r\n");
|
||||
fwrite(html_video_html, 1, html_video_html_len, stream);
|
||||
fflush(stream);
|
||||
}
|
||||
|
||||
void http_jmuxer_js(http_worker_t *worker, FILE *stream)
|
||||
{
|
||||
extern unsigned char html_jmuxer_min_js[];
|
||||
extern unsigned int html_jmuxer_min_js_len;
|
||||
|
||||
fprintf(stream, "HTTP/1.1 200 OK\r\n");
|
||||
fprintf(stream, "Content-Type: text/javascript;charset=UTF-8\r\n");
|
||||
fprintf(stream, "\r\n");
|
||||
fwrite(html_jmuxer_min_js, 1, html_jmuxer_min_js_len, stream);
|
||||
fflush(stream);
|
||||
http_write_response(stream, "500 Server Error", NULL, data ? data : "Server Error\n", 0);
|
||||
}
|
||||
|
Reference in New Issue
Block a user