Exemplo n.º 1
0
static boolean file_handler(TinyWebServer& web_server)
{
	const char *path = web_server.get_path();
	Serial << "GET " << path << '\n';

	if (strcmp(path, "/") == 0) path = "/index.html";

	const struct httpd_fsdata_segment *segment;
	int len;
	bool use_gzip;

	if (find_file(path, &segment, &len, &use_gzip)) {
		web_server.send_error_code(200);
		web_server.send_last_modified("Wed, 21 Oct 2015 07:28:00 GMT");
		web_server.send_content_type(web_server.get_mime_type_from_filename(path));
		if (use_gzip) web_server.write("Content-Encoding: gzip\n");
		web_server.end_headers(); 
	
		while (segment && len > 0) {
			char *data = (char *)pgm_read_word(&(segment->data));
			int i;
			int segment_len = min(len, httpd_fsdata_segment_len);
			
			while (segment_len > 0) {
				uint8_t buf[256];
				int i;
				for (i = 0; i < segment_len && i < sizeof(buf); i++) {
					buf[i] = pgm_read_byte(data++);
				}
				segment_len -= i;
				len -= i;
				web_server.write(buf, i);
			}
			segment = (const struct httpd_fsdata_segment *)pgm_read_word(&(segment->next));
		}
	}
	else {
		web_server.send_error_code(404);
		web_server.send_content_type("text/plain");
		web_server.end_headers();
		web_server.print("not found");
	}

	return true;
}
Exemplo n.º 2
0
static boolean reboot_handler(TinyWebServer& web_server)
{
	web_server.send_error_code(200);
	web_server.send_content_type("text/plain");
	web_server.end_headers();
	web_server.write("rebooting");
	doReset = true;
	return true;
}