当前位置: 首页>>代码示例>>C++>>正文


C++ end_headers函数代码示例

本文整理汇总了C++中end_headers函数的典型用法代码示例。如果您正苦于以下问题:C++ end_headers函数的具体用法?C++ end_headers怎么用?C++ end_headers使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了end_headers函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: get_info_refs

static void get_info_refs(char *arg)
{
	const char *service_name = get_parameter("service");
	struct strbuf buf = STRBUF_INIT;

	hdr_nocache();

	if (service_name) {
		const char *argv[] = {NULL /* service name */,
			"--stateless-rpc", "--advertise-refs",
			".", NULL};
		struct rpc_service *svc = select_service(service_name);

		strbuf_addf(&buf, "application/x-git-%s-advertisement",
			svc->name);
		hdr_str(content_type, buf.buf);
		end_headers();

		packet_write(1, "# service=git-%s\n", svc->name);
		packet_flush(1);

		argv[0] = svc->name;
		run_service(argv);

	} else {
		select_getanyfile();
		for_each_namespaced_ref(show_text_ref, &buf);
		send_strbuf("text/plain", &buf);
	}
	strbuf_release(&buf);
}
开发者ID:120011676,项目名称:git,代码行数:31,代码来源:http-backend.c

示例2: send_strbuf

static void send_strbuf(const char *type, struct strbuf *buf)
{
	hdr_int(content_length, buf->len);
	hdr_str(content_type, type);
	end_headers();
	write_or_die(1, buf->buf, buf->len);
}
开发者ID:120011676,项目名称:git,代码行数:7,代码来源:http-backend.c

示例3: send_local_file

static void send_local_file(const char *the_type, const char *name)
{
	const char *p = git_path("%s", name);
	size_t buf_alloc = 8192;
	char *buf = xmalloc(buf_alloc);
	int fd;
	struct stat sb;

	fd = open(p, O_RDONLY);
	if (fd < 0)
		not_found("Cannot open '%s': %s", p, strerror(errno));
	if (fstat(fd, &sb) < 0)
		die_errno("Cannot stat '%s'", p);

	hdr_int(content_length, sb.st_size);
	hdr_str(content_type, the_type);
	hdr_date(last_modified, sb.st_mtime);
	end_headers();

	for (;;) {
		ssize_t n = xread(fd, buf, buf_alloc);
		if (n < 0)
			die_errno("Cannot read '%s'", p);
		if (!n)
			break;
		write_or_die(1, buf, n);
	}
	close(fd);
	free(buf);
}
开发者ID:120011676,项目名称:git,代码行数:30,代码来源:http-backend.c

示例4: die_webcgi

static NORETURN void die_webcgi(const char *err, va_list params)
{
	if (dead <= 1) {
		vreportf("fatal: ", err, params);

		http_status(500, "Internal Server Error");
		hdr_nocache();
		end_headers();
	}
	exit(0); /* we successfully reported a failure ;-) */
}
开发者ID:1tgr,项目名称:git,代码行数:11,代码来源:http-backend.c

示例5: F

void MiniWebServer::send_error_code(Client& client, int code) {
#if DEBUG
    Serial << F("TWS:Returning ");
    Serial.println(code, DEC);
#endif
    client << F("HTTP/1.1 ");
    client.print(code, DEC);
    client << F(" OK\r\n");
    if (code != 200) {
        end_headers(client);
    }
}
开发者ID:masgari,项目名称:MiniWebServer,代码行数:12,代码来源:MiniWebServer.cpp

示例6: forbidden

static NORETURN void forbidden(const char *err, ...)
{
	va_list params;

	http_status(403, "Forbidden");
	hdr_nocache();
	end_headers();

	va_start(params, err);
	if (err && *err)
		vfprintf(stderr, err, params);
	va_end(params);
	exit(0);
}
开发者ID:120011676,项目名称:git,代码行数:14,代码来源:http-backend.c

示例7: not_found

static NORETURN void not_found(const char *err, ...)
{
	va_list params;

	http_status(404, "Not Found");
	hdr_nocache();
	end_headers();

	va_start(params, err);
	if (err && *err)
		vfprintf(stderr, err, params);
	va_end(params);
	exit(0);
}
开发者ID:120011676,项目名称:git,代码行数:14,代码来源:http-backend.c

示例8: bad_request

static int bad_request(struct strbuf *hdr, const struct service_cmd *c)
{
	const char *proto = getenv("SERVER_PROTOCOL");

	if (proto && !strcmp(proto, "HTTP/1.1")) {
		http_status(hdr, 405, "Method Not Allowed");
		hdr_str(hdr, "Allow",
			!strcmp(c->method, "GET") ? "GET, HEAD" : c->method);
	} else
		http_status(hdr, 400, "Bad Request");
	hdr_nocache(hdr);
	end_headers(hdr);
	return 0;
}
开发者ID:9b,项目名称:git,代码行数:14,代码来源:http-backend.c

示例9: die_webcgi

static NORETURN void die_webcgi(const char *err, va_list params)
{
	static int dead;

	if (!dead) {
		char buffer[1000];
		dead = 1;

		vsnprintf(buffer, sizeof(buffer), err, params);
		fprintf(stderr, "fatal: %s\n", buffer);
		http_status(500, "Internal Server Error");
		hdr_nocache();
		end_headers();
	}
	exit(0); /* we successfully reported a failure ;-) */
}
开发者ID:Provab-Solutions,项目名称:git,代码行数:16,代码来源:http-backend.c

示例10: fetch_file

int fetch_file(int connfd, const char *filename) {
    int fd, fsize;
    struct stat fs;
    void *mblock;
    const char *mime_type, *suffix;
    int i;

    fd = open(filename, O_RDONLY);
    fstat(fd, &fs);
    fsize = fs.st_size;
    mblock = mmap(NULL, fsize, PROT_WRITE, MAP_PRIVATE, fd, 0);
    if (mblock == MAP_FAILED) {
        close(fd);
        send_error(connfd, 404);
        return 0;
    }

    suffix = filename;
    for (i = (int) strlen(filename) - 1; i >= 0; --i) {
        if (filename[i] == '.') {
            suffix = filename + i;
            break;
        }
    }

    if (strcasecmp(suffix, ".html") == 0 || strcasecmp(suffix, ".htm") == 0) {
        mime_type = "text/html";
    } else if (strcasecmp(suffix, ".css") == 0) {
        mime_type = "text/css";
    } else if (strcasecmp(suffix, ".js") == 0) {
        mime_type = "application/x-javascript";
    } else if (strcasecmp(suffix, ".c") == 0 || strcasecmp(suffix, ".h") == 0) {
        mime_type = "text/plain";
    } else {
        mime_type = "application/octet-stream";
    }

    send_response(connfd, 200, NULL);
    send_header(connfd, "Content-Type", mime_type);
    send_header(connfd, "Content-Length", "%d", fsize);
    end_headers(connfd);

    rio_writen(connfd, mblock, fsize);
    munmap(mblock, fsize);

    return 1;
}
开发者ID:foreverbell,项目名称:playground,代码行数:47,代码来源:http-server.c

示例11: check_content_type

static void check_content_type(const char *accepted_type)
{
	const char *actual_type = getenv("CONTENT_TYPE");

	if (!actual_type)
		actual_type = "";

	if (strcmp(actual_type, accepted_type)) {
		http_status(415, "Unsupported Media Type");
		hdr_nocache();
		end_headers();
		format_write(1,
			"Expected POST with Content-Type '%s',"
			" but received '%s' instead.\n",
			accepted_type, actual_type);
		exit(0);
	}
}
开发者ID:120011676,项目名称:git,代码行数:18,代码来源:http-backend.c

示例12: send_error

void send_error(int connfd, int code) {
    char *buf = (char *) malloc(MAXBUF);
    const char *message = lookup_resp(code)->resp_msg;

    send_response(connfd, code, message);
    send_header(connfd, "Content-Type", "text/html");
    send_header(connfd, "Connection", "close");
    end_headers(connfd);

    snprintf(buf, MAXBUF,
             "<head>\n"
             "<title>Error Response</title>\n"
             "</head>\n"
             "<body>\n"
             "<h1>Error Response</h1>\n"
             "<p>Error code %d.</p>\n"
             "<p>Message: %s.</p>\n"
             "</body>", code, message);
    rio_writen(connfd, buf, strlen(buf));

    free(buf);
}
开发者ID:foreverbell,项目名称:playground,代码行数:22,代码来源:http-server.c

示例13: service_rpc

static void service_rpc(char *service_name)
{
	const char *argv[] = {NULL, "--stateless-rpc", ".", NULL};
	struct rpc_service *svc = select_service(service_name);
	struct strbuf buf = STRBUF_INIT;

	strbuf_reset(&buf);
	strbuf_addf(&buf, "application/x-git-%s-request", svc->name);
	check_content_type(buf.buf);

	hdr_nocache();

	strbuf_reset(&buf);
	strbuf_addf(&buf, "application/x-git-%s-result", svc->name);
	hdr_str(content_type, buf.buf);

	end_headers();

	argv[0] = svc->name;
	run_service(argv);
	strbuf_release(&buf);
}
开发者ID:120011676,项目名称:git,代码行数:22,代码来源:http-backend.c

示例14: F

void TinyWebServer::send_error_code(Client& client, int code) {
#if DEBUG
  Serial << F("TWS:Returning ");
  Serial.println(code, DEC);
#endif
  client << F("HTTP/1.1 ");
  client.print(code, DEC);
  if (code==200)
    client << F(" OK\r\n");
  else if (code==400)
    client << F(" Bad Request\r\n");
  else if (code==404)
    client << F(" Not Found\r\n");
  else if (code==414)
    client << F(" Request URI Too Long\r\n");
  else if (code==417)
    client << F(" Expectation Failed\r\n");
  client << F("Connection: close\r\n");
  client << F("Cache-Control: no-cache\r\n");
  if (code != 200) {
    end_headers(client);
  }
}
开发者ID:d0ughb0y,项目名称:Chauvet16,代码行数:23,代码来源:TinyWebServer.cpp

示例15: list_directory

int list_directory(int connfd, const char *dirname) {
    char *buf;
    DIR *d;
    struct dirent *dir;
    struct stat fs;
    const char *item_fmt;
    const char *filename;
    char *fullname;
    int len1, len2, nwritten = 0;
    int ret;

    d = opendir(dirname);
    if (d) {

        buf = (char *) malloc(MAXBUF);

        /* TODO: escape or quote dirname / filename */
        nwritten += snprintf(buf + nwritten, MAXBUF - nwritten,
                             "<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 3.2 Final//EN\">\n"
                             "<html>\n"
                             "<title>Directory listing for %s</title>\n"
                             "<body>\n"
                             "<h2>Directory listing for %s</h2>\n"
                             "<hr>\n"
                             "<ul>\n", dirname + 1, dirname + 1);

        while ((dir = readdir(d)) != NULL) {
            filename = dir->d_name;

            if (strcmp(filename, ".") == 0 || strcmp(filename, "..") == 0) {
                continue;
            } else {
                len1 = strlen(dirname);
                len2 = strlen(filename);
                fullname = (char *) malloc(len1 + len2 + 1);
                strcpy(fullname, dirname);
                strcpy(fullname + len1, filename);
                fullname[len1 + len2] = 0;

                if (strcasecmp(filename, "index.html") == 0 || strcasecmp(filename, "index.htm") == 0) {
                    ret = fetch_file(connfd, fullname);
                    free(fullname);
                    free(buf);
                    closedir(d);
                    return ret;
                } else {
                    stat(fullname, &fs);
                    if (S_ISDIR(fs.st_mode)) {
                        item_fmt = "<li><a href=\"%s/\">%s/</a>\n";
                    } else {
                        item_fmt = "<li><a href=\"%s\">%s</a>\n";
                    }
                    nwritten += snprintf(buf + nwritten, MAXBUF - nwritten,
                                         item_fmt, filename, filename);
                }

                free(fullname);
            }
        }
        closedir(d);

        nwritten += snprintf(buf + nwritten, MAXBUF - nwritten,
                             "</ul>\n"
                             "<hr>\n"
                             "</body>\n"
                             "</html>\n");

        send_response(connfd, 200, NULL);
        send_header(connfd, "Content-Type", "text/html");
        send_header(connfd, "Content-Length", "%d", nwritten);
        end_headers(connfd);
        rio_writen(connfd, buf, nwritten);

        free(buf);

        return 1;
    }

    send_error(connfd, 404);

    return 0;
}
开发者ID:foreverbell,项目名称:playground,代码行数:82,代码来源:http-server.c


注:本文中的end_headers函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。