Esempio n. 1
0
static inline void httpd_receive_header(struct http_state *http, char c)
{
	char *line = httpd_receive_char(http, c);
	if (!line)
		return;
	
		/* empty line? */
	if (line[0] == '\n')
	{
		httpd_start_response(http);
		return;
	}
	
	char *val = line;
	while (*val)
	{
		if (*val == ':')
		{
			*val++=0;
			if (*val == ' ')
				val++;
			break;
		}
		++val;
	}
	
	if (val[strlen(val)-1]=='\n')
		val[strlen(val)-1]=0;

	hdprintf("received client header %s:%s\n", line, val);
	if (http->handler->process_header)
		http->handler->process_header(http, line, val);
}
Esempio n. 2
0
static inline void httpd_receive_request(struct http_state *http, char c) {
    char *line = httpd_receive_char(http, c);
    if (!line)
        return;

    char *method = line;
    char *path = line;
    while (*path) {
        if (*path == ' ') {
            *path++ = 0;
            break;
        }
        ++path;
    }

    char *version = path;
    while (*version) {
        if (*version == ' ') {
            *version++ = 0;
            break;
        }
        ++version;
    }

    if ((!*path) || (!*version) || strncmp(version, "HTTP/1.", 7)) {
        http->code = 400;
        path = "";
    }

    hdprintf("received client Request: method=%s path=%s\n", method, path);

    httpd_find_handler(http, method, path);

    http->state_client = HTTPD_CLIENT_HEADER;
}