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


C++ MHD_add_response_header函数代码示例

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


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

示例1: send_redirect_temp

int send_redirect_temp(struct MHD_Connection *connection, const char *url)
{
	struct MHD_Response *response;
	int ret;
	char *redirect = NULL;

	const char *redirect_body = "<html><head></head><body><a href='%s'>Click here to continue to<br>%s</a></body></html>";
	safe_asprintf(&redirect, redirect_body, url, url);

	response = MHD_create_response_from_buffer(strlen(redirect), redirect, MHD_RESPMEM_MUST_FREE);
	if (!response)
		return send_error(connection, 503);

	// MHD_set_response_options(response, MHD_RF_HTTP_VERSION_1_0_ONLY, MHD_RO_END);
	MHD_add_response_header(response, "Location", url);
	MHD_add_response_header(response, "Connection", "close");
	ret = MHD_queue_response(connection, MHD_HTTP_TEMPORARY_REDIRECT, response);
	MHD_destroy_response(response);

	return ret;
}
开发者ID:lynxis,项目名称:nodogsplash,代码行数:21,代码来源:http_microhttpd.c

示例2: MHD_create_response_from_buffer

/**
* Handle incoming HTTP requests
**/
int CmdManager::AccessHandlerCallback(
    struct MHD_Connection* connection,
    const char* url, const char* method,
    const char* upload_data, size_t* upload_data_size,
    void** ptr
) {
    static int dummy;
    struct MHD_Response* response;
    int ret;

    if (0 != strcmp(method, "GET")) {
        return MHD_NO; /* unexpected method */
    }

    // The first time only the headers are valid, so store data but don't respond
    if (&dummy != *ptr) {
        *ptr = &dummy;
        return MHD_YES;
    }

    if (0 != *upload_data_size) {
        return MHD_NO; /* upload data in a GET!? */
    }

    // clear context pointer
    *ptr = NULL;

    Cmd* c = this->dispatch(connection, url, method);
    if (c == NULL) {
        return MHD_NO;
    }
    work.push(c);
    std::string resp = c->waitDone();
    delete c;

    response = MHD_create_response_from_buffer(
        resp.length(),
        (void*) resp.c_str(),
        MHD_RESPMEM_MUST_COPY
    );

    // Allows other origins to access data via AJAX
    MHD_add_response_header(response, "Access-Control-Allow-Origin", "*");

    ret = MHD_queue_response(
        connection,
        MHD_HTTP_OK,
        response
    );
    MHD_destroy_response(response);

    return ret;
}
开发者ID:TheJosh,项目名称:chaotic-rage,代码行数:56,代码来源:cmd_manager.cpp

示例3: SendTemplate

static int SendTemplate(MHD_Connection* connection, bool redirect = false,
                        const char* redirectUrl = nullptr) {
    SkString debuggerTemplate = generateTemplate(SkString(FLAGS_source[0]));

    MHD_Response* response = MHD_create_response_from_buffer(
                                 debuggerTemplate.size(),
                                 (void*) const_cast<char*>(debuggerTemplate.c_str()),
                                 MHD_RESPMEM_MUST_COPY);
    MHD_add_response_header (response, "Access-Control-Allow-Origin", "*");

    int status = MHD_HTTP_OK;

    if (redirect) {
        MHD_add_response_header (response, "Location", redirectUrl);
        status = MHD_HTTP_SEE_OTHER;
    }

    int ret = MHD_queue_response(connection, status, response);
    MHD_destroy_response(response);
    return ret;
}
开发者ID:mokacao,项目名称:skia,代码行数:21,代码来源:skiaserve.cpp

示例4: webu_stream_static

int webu_stream_static(struct webui_ctx *webui) {
    /* Create the response for the static image request*/
    int retcd;
    struct MHD_Response *response;
    char resp_used[20];

    if (webu_stream_checks(webui) == -1) return MHD_NO;

    webu_stream_cnct_count(webui);

    webu_stream_mjpeg_checkbuffers(webui);

    webu_stream_static_getimg(webui);

    if (webui->resp_used == 0) {
        MOTION_LOG(ERR, TYPE_STREAM, NO_ERRNO, _("Could not get image to stream."));
        return MHD_NO;
    }

    response = MHD_create_response_from_buffer (webui->resp_size
        ,(void *)webui->resp_page, MHD_RESPMEM_MUST_COPY);
    if (!response){
        MOTION_LOG(ERR, TYPE_STREAM, NO_ERRNO, _("Invalid response"));
        return MHD_NO;
    }

    if (webui->cnt->conf.stream_cors_header != NULL){
        MHD_add_response_header (response, MHD_HTTP_HEADER_ACCESS_CONTROL_ALLOW_ORIGIN
            , webui->cnt->conf.stream_cors_header);
    }

    MHD_add_response_header (response, MHD_HTTP_HEADER_CONTENT_TYPE, "image/jpeg;");
    snprintf(resp_used, 20, "%9ld\r\n\r\n",(long)webui->resp_used);
    MHD_add_response_header (response, MHD_HTTP_HEADER_CONTENT_LENGTH, resp_used);

    retcd = MHD_queue_response (webui->connection, MHD_HTTP_OK, response);
    MHD_destroy_response (response);

    return retcd;
}
开发者ID:Motion-Project,项目名称:motion,代码行数:40,代码来源:webu_stream.c

示例5: sendMethodNotAllowedResponse

inline int sendMethodNotAllowedResponse(struct MHD_Connection* connection, bool allowGet) {
    struct MHD_Response* response;
    int ret;

#ifdef MICROHTTPD_DEPRECATED
    response = MHD_create_response_from_data(
        strlen(XML_MWS_METHOD_NOT_ALLOWED), (void*)XML_MWS_METHOD_NOT_ALLOWED, false, false);
#else  // MICROHTTPD_DEPRECATED
    response = MHD_create_response_from_buffer(
        strlen(XML_MWS_METHOD_NOT_ALLOWED), (void*)XML_MWS_METHOD_NOT_ALLOWED, MHD_RESPMEM_PERSISTENT);
#endif  // MICROHTTPD_DEPRECATED
    MHD_add_response_header(response, "Content-Type", "text/xml");
    MHD_add_response_header(response, "Allow",
                            allowGet ? "GET, POST, OPTIONS" : "POST, OPTIONS");
    MHD_add_response_header(response, "Access-Control-Allow-Origin", "*");
    MHD_add_response_header(response, "Allow",
                            allowGet ? "GET, POST, OPTIONS" : "POST, OPTIONS");
    MHD_add_response_header(response, "Access-Control-Allow-Headers",
                            "CONTENT-TYPE");
    MHD_add_response_header(response, "Access-Control-Max-Age", "1728000");
    ret = MHD_queue_response(connection, MHD_HTTP_METHOD_NOT_ALLOWED, response);
    MHD_destroy_response(response);

    return ret;
}
开发者ID:KWARC,项目名称:mws,代码行数:25,代码来源:GenericHttpResponses.hpp

示例6: send_page

// This function sends some answer string back to the Client.
static int send_page(struct MHD_Connection *connection, unsigned int status_code, const char *page)
{
    int ret;
    struct MHD_Response *response;
    response = MHD_create_response_from_buffer(strlen(page), (void *) page, MHD_RESPMEM_MUST_COPY);
    MHD_add_response_header(response, MHD_HTTP_HEADER_CONTENT_ENCODING, "text/plain");
    if (!response) {
        return MHD_NO;
    }
    ret = MHD_queue_response(connection, status_code, response);
    MHD_destroy_response(response);
    return ret;
}
开发者ID:neopostmodern,项目名称:grundlagen-der-technischen-informatik,代码行数:14,代码来源:block5.c

示例7: MHD_create_response_from_buffer

//---- Creating response page with right header syntaxe
int Server::send_page(MHD_Connection *connection, const char *page, int length, int status_code, const char * type){
    
    struct MHD_Response *response;
    
    response = MHD_create_response_from_buffer(length, (void*)page,
                                               MHD_RESPMEM_PERSISTENT);
    if (!response) {
        return MHD_NO;
    }
    
    MHD_add_response_header(response, "Content-Type", type ? type : "text/plain");

    return MHD_queue_response(connection, status_code, response);
}
开发者ID:FlatIO,项目名称:faudiostream,代码行数:15,代码来源:Server.cpp

示例8: sendOptionsResponse

inline int sendOptionsResponse(struct MHD_Connection* connection, bool allowGet) {
    struct MHD_Response* response;
    int ret;

#ifdef MICROHTTPD_DEPRECATED
    response = MHD_create_response_from_data(
        strlen(EMPTY_RESPONSE), (void*)EMPTY_RESPONSE, false, false);
#else  // MICROHTTPD_DEPRECATED
    response = MHD_create_response_from_buffer(
        strlen(EMPTY_RESPONSE), (void*)EMPTY_RESPONSE, MHD_RESPMEM_PERSISTENT);
#endif  // MICROHTTPD_DEPRECATED
    MHD_add_response_header(response, "Content-Type", "text/plain");
    MHD_add_response_header(response, "Access-Control-Allow-Origin", "*");
    MHD_add_response_header(response, "Access-Control-Allow-Methods",
                            allowGet ? "GET, POST, OPTIONS" : "POST, OPTIONS");
    MHD_add_response_header(response, "Access-Control-Allow-Headers",
                            "CONTENT-TYPE");
    MHD_add_response_header(response, "Access-Control-Max-Age", "1728000");
    ret = MHD_queue_response(connection, MHD_HTTP_OK, response);
    MHD_destroy_response(response);

    return ret;
}
开发者ID:KWARC,项目名称:mws,代码行数:23,代码来源:GenericHttpResponses.hpp

示例9: crc

/**
 * MHD content reader callback that returns
 * data in chunks.
 */
static int
crc (void *cls, size_t pos, char *buf, int max)
{
  struct MHD_Response **responseptr = cls;

  if (pos == 128 * 10)
    {
      MHD_add_response_header (*responseptr, "Footer", "working");
      return -1;                /* end of stream */
    }
  if (max < 128)
    abort ();                   /* should not happen in this testcase... */
  memset (buf, 'A' + (pos / 128), 128);
  return 128;
}
开发者ID:dreamsxin,项目名称:golf,代码行数:19,代码来源:daemontest_get_chunked.c

示例10: MHD_add_response_header

void http_response::decorate_response_str(MHD_Response* response)
{
    map<string, string, header_comparator>::iterator it;

    for (it=headers.begin() ; it != headers.end(); ++it)
        MHD_add_response_header(
                response,
                (*it).first.c_str(),
                (*it).second.c_str()
        );

    for (it=footers.begin() ; it != footers.end(); ++it)
        MHD_add_response_footer(response,
                (*it).first.c_str(),
                (*it).second.c_str()
        );

    for (it=cookies.begin(); it != cookies.end(); ++it)
        MHD_add_response_header(
                response,
                "Set-Cookie",
                ((*it).first + "=" + (*it).second).c_str()
        );
}
开发者ID:AlgoPeek,项目名称:libhttpserver,代码行数:24,代码来源:http_response.cpp

示例11: web_send_data

/*
 * web_send_data
 * Send internal HTML string
 */
static int web_send_data (struct MHD_Connection *connection, const char *data,
		const int code, bool free, bool copy, const char *ct)
{
	struct MHD_Response *response;
	int ret;

	response = MHD_create_response_from_data(strlen(data), (void *)data, free ? MHD_YES : MHD_NO, copy ? MHD_YES : MHD_NO);
	if (response == NULL)
		return MHD_NO;
	if (ct != NULL)
		MHD_add_response_header(response, "Content-type", ct);
	ret = MHD_queue_response(connection, code, response);
	MHD_destroy_response(response);
	return ret;
}
开发者ID:zombie9080,项目名称:libmicrohttpd-test,代码行数:19,代码来源:webserver.cpp

示例12: crc

/**
 * MHD content reader callback that returns
 * data in chunks.
 */
static ssize_t
crc (void *cls, uint64_t pos, char *buf, size_t max)
{
  struct MHD_Response **responseptr = cls;

  if (pos == 128 * 10)
    {
      MHD_add_response_header (*responseptr, "Footer", "working");
      return MHD_CONTENT_READER_END_OF_STREAM;
    }
  if (max < 128)
    abort ();                   /* should not happen in this testcase... */
  memset (buf, 'A' + (pos / 128), 128);
  return 128;
}
开发者ID:AlgoPeek,项目名称:libmicrohttpd,代码行数:19,代码来源:test_get_chunked.c

示例13: serve_file

/**
 * @brief serve_file try to serve a request via filesystem. Using webroot as root.
 * @param connection
 * @param client
 * @return
 */
static int serve_file(struct MHD_Connection *connection, t_client *client, const char *url)
{
	struct stat stat_buf;
	s_config *config = config_get_config();
	struct MHD_Response *response;
	char filename[PATH_MAX];
	int ret = MHD_NO;
	const char *mimetype = NULL;
	off_t size;

	snprintf(filename, PATH_MAX, "%s/%s", config->webroot, url);

	/* check if file exists and is not a directory */
	ret = stat(filename, &stat_buf);
	if (ret) {
		/* stat failed */
		return send_error(connection, 404);
	}

	if (!S_ISREG(stat_buf.st_mode)) {
#ifdef S_ISLNK
		/* ignore links */
		if (!S_ISLNK(stat_buf.st_mode))
#endif /* S_ISLNK */
		return send_error(connection, 404);
	}

	int fd = open(filename, O_RDONLY);
	if (fd < 0)
		return send_error(connection, 404);

	mimetype = lookup_mimetype(filename);

	/* serving file and creating response */
	size = lseek(fd, 0, SEEK_END);
	if (size < 0)
		return send_error(connection, 404);

	response = MHD_create_response_from_fd(size, fd);
	if (!response)
		return send_error(connection, 503);

	MHD_add_response_header(response, "Content-Type", mimetype);
	ret = MHD_queue_response(connection, MHD_HTTP_OK, response);
	MHD_destroy_response(response);

	return ret;
}
开发者ID:zaolin,项目名称:nodogsplash,代码行数:54,代码来源:http_microhttpd.c

示例14: ahc_echo

int ahc_echo(void* servctx, MHD_Connection* connection, const char* url, const char* method, const char* version, const char* upload_data, size_t* upload_data_size, void** reqctx)
{
	static int dummy;
	if (reqctx == NULL)
	{
		// The first time only the headers are valid, do not respond in the first round.
		*reqctx = &dummy;
		return MHD_YES;
	}

	ServerContext* pServCtx = (ServerContext*)servctx;	// Not used yet
	printf("%s %s %s\n", method, url, version);

	if (strcmp(method, "GET") == 0)
	{
		if (*upload_data_size != 0)
			return MHD_NO;	// No upload data expected in HTTP GET method
 
		// Parse headers
		puts("[HEADERS]");
		MHD_get_connection_values(connection, MHD_HEADER_KIND, &print_out_key, NULL);

		// Parse GET parameters
		puts("[GET PARAMS]");
		StringPairList spl;
		MHD_get_connection_values(connection, MHD_GET_ARGUMENT_KIND, &print_out_key, &spl);

		std::string text = "<html><body>\n";
		text += "<p>URL="; text += url; 
		text += "</p>\n<p>Parameters</p>\n<ul>\n";
		for (StringPairList::iterator it = spl.begin(); it != spl.end(); ++it)
		{
			text += "<li>"; text += it->first; text += '='; text += it->second; text += "</li>\n";
		}
		text += "</body></html>\n";

		MHD_Response* response = MHD_create_response_from_buffer(text.size(), (void*)text.c_str(), MHD_RESPMEM_MUST_COPY);
		MHD_add_response_header(response, "Content-Type", "text/html");
		int ret = MHD_queue_response(connection, MHD_HTTP_OK, response);
		MHD_destroy_response(response);

		*reqctx = NULL; // clear context pointer
		return ret;
	}
	else
		return MHD_NO;	// Not supported yet
}
开发者ID:Jerryang,项目名称:cdec,代码行数:47,代码来源:02.cpp

示例15: ServeMainPage

/**
 * Handler that adds the 'v1' value to the given HTML code.
 *
 * @param cls unused
 * @param mime mime type to use
 * @param session session handle
 * @param connection connection to use
 */
static int
ServeMainPage (const void *cls,
	      const char *mime,
	      struct Session *session,
	      struct MHD_Connection *connection)
{
  int ret;
  char *reply;
  struct MHD_Response *response;
  
  reply = malloc(MAXTEXTFILELENGTH);
  if (NULL == reply)
    return MHD_NO;  
  if ( !ReadTextFileIntoString(reply, "data/MainPage.html") )
    return MHD_NO;  

/*    
  // Open the MainPage html file
  FILE *fp = fopen("data/MainPage.html", "rb");
  if (NULL == fp)
	  return MHD_NO;
  fseek(fp, 0L, SEEK_END);
  long sz = ftell(fp);
  fseek(fp, 0L, SEEK_SET);
  reply = malloc (sz+1);
  if (NULL == reply)
    return MHD_NO;
  fread (reply, 1, sz, fp);
  fclose (fp);
 */

  /* return static form */
  response = MHD_create_response_from_buffer (strlen (reply),
					      (void *) reply,
					      MHD_RESPMEM_MUST_FREE);
  if (NULL == response)
    return MHD_NO;
  add_session_cookie (session, response);
  MHD_add_response_header (response,
			   MHD_HTTP_HEADER_CONTENT_ENCODING,
			   mime);
  ret = MHD_queue_response (connection,
			    MHD_HTTP_OK,
			    response);
  MHD_destroy_response (response);
  return ret;
}
开发者ID:riccardoventrella,项目名称:HIDWebServer,代码行数:55,代码来源:WebServer.c


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