示例#1
0
static void httpsServerCallback(SoupServer* server, SoupMessage* message, const char* path, GHashTable*, SoupClientContext*, gpointer)
{
    if (message->method != SOUP_METHOD_GET) {
        soup_message_set_status(message, SOUP_STATUS_NOT_IMPLEMENTED);
        return;
    }

    if (g_str_equal(path, "/")) {
        soup_message_set_status(message, SOUP_STATUS_OK);
        soup_message_body_append(message->response_body, SOUP_MEMORY_STATIC, indexHTML, strlen(indexHTML));
        soup_message_body_complete(message->response_body);
    } else if (g_str_equal(path, "/insecure-content/")) {
        GUniquePtr<char> responseHTML(g_strdup_printf(insecureContentHTML, kHttpServer->getURIForPath("/test-script").data(), kHttpServer->getURIForPath("/test-image").data()));
        soup_message_body_append(message->response_body, SOUP_MEMORY_COPY, responseHTML.get(), strlen(responseHTML.get()));
        soup_message_set_status(message, SOUP_STATUS_OK);
        soup_message_body_complete(message->response_body);
    } else if (g_str_equal(path, "/test-tls/")) {
        soup_message_set_status(message, SOUP_STATUS_OK);
        soup_message_body_append(message->response_body, SOUP_MEMORY_STATIC, TLSSuccessHTMLString, strlen(TLSSuccessHTMLString));
        soup_message_body_complete(message->response_body);
    } else if (g_str_equal(path, "/redirect")) {
        soup_message_set_status(message, SOUP_STATUS_MOVED_PERMANENTLY);
        soup_message_headers_append(message->response_headers, "Location", kHttpServer->getURIForPath("/test-image").data());
    } else if (g_str_equal(path, "/auth")) {
        soup_message_set_status(message, SOUP_STATUS_UNAUTHORIZED);
        soup_message_headers_append(message->response_headers, "WWW-Authenticate", "Basic realm=\"HTTPS auth\"");
    } else
        soup_message_set_status(message, SOUP_STATUS_NOT_FOUND);
}
static void
serverCallback(SoupServer* server, SoupMessage* message, const char* path, GHashTable* query, SoupClientContext* context, void* data)
{
    if (message->method != SOUP_METHOD_GET) {
        soup_message_set_status(message, SOUP_STATUS_NOT_IMPLEMENTED);
        return;
    }

    if (g_str_equal(path, "/favicon.ico")) {
        soup_message_set_status(message, SOUP_STATUS_NOT_FOUND);
        soup_message_body_complete(message->response_body);
        return;
    }

    char* contents;
    gsize length;
    if (g_str_equal(path, "/icon/favicon.ico")) {
        GUniquePtr<char> pathToFavicon(g_build_filename(Test::getResourcesDir().data(), "blank.ico", nullptr));
        g_file_get_contents(pathToFavicon.get(), &contents, &length, 0);
        soup_message_body_append(message->response_body, SOUP_MEMORY_TAKE, contents, length);
    } else if (g_str_equal(path, "/nofavicon")) {
        static const char* noFaviconHTML = "<html><head><body>test</body></html>";
        soup_message_body_append(message->response_body, SOUP_MEMORY_STATIC, noFaviconHTML, strlen(noFaviconHTML));
    } else {
        static const char* contentsHTML = "<html><head><link rel='icon' href='/icon/favicon.ico' type='image/x-ico; charset=binary'></head><body>test</body></html>";
        soup_message_body_append(message->response_body, SOUP_MEMORY_STATIC, contentsHTML, strlen(contentsHTML));
    }

    soup_message_set_status(message, SOUP_STATUS_OK);
    soup_message_body_complete(message->response_body);
}
示例#3
0
static void serverCallback(SoupServer* server, SoupMessage* message, const char* path, GHashTable*, SoupClientContext*, gpointer)
{
    if (message->method != SOUP_METHOD_GET) {
        soup_message_set_status(message, SOUP_STATUS_NOT_IMPLEMENTED);
        return;
    }

    if (g_str_equal(path, "/")) {
        const char* acceptLanguage = soup_message_headers_get_one(message->request_headers, "Accept-Language");
        soup_message_set_status(message, SOUP_STATUS_OK);
        soup_message_body_append(message->response_body, SOUP_MEMORY_COPY, acceptLanguage, strlen(acceptLanguage));
        soup_message_body_complete(message->response_body);
    } else if (g_str_equal(path, "/empty")) {
        const char* emptyHTML = "<html><body></body></html>";
        soup_message_body_append(message->response_body, SOUP_MEMORY_STATIC, emptyHTML, strlen(emptyHTML));
        soup_message_body_complete(message->response_body);
        soup_message_set_status(message, SOUP_STATUS_OK);
    } else if (g_str_equal(path, "/appcache")) {
        const char* appcacheHTML = "<html manifest=appcache.manifest><body></body></html>";
        soup_message_body_append(message->response_body, SOUP_MEMORY_STATIC, appcacheHTML, strlen(appcacheHTML));
        soup_message_body_complete(message->response_body);
        soup_message_set_status(message, SOUP_STATUS_OK);
    } else if (g_str_equal(path, "/appcache.manifest")) {
        const char* appcacheManifest = "CACHE MANIFEST\nCACHE:\nappcache/foo.txt\n";
        soup_message_body_append(message->response_body, SOUP_MEMORY_STATIC, appcacheManifest, strlen(appcacheManifest));
        soup_message_body_complete(message->response_body);
        soup_message_set_status(message, SOUP_STATUS_OK);
    } else if (g_str_equal(path, "/appcache/foo.txt")) {
        soup_message_body_append(message->response_body, SOUP_MEMORY_STATIC, "foo", 3);
        soup_message_body_complete(message->response_body);
        soup_message_set_status(message, SOUP_STATUS_OK);
    } else
        soup_message_set_status(message, SOUP_STATUS_NOT_FOUND);
}
示例#4
0
文件: TestSSL.cpp 项目: jiezh/h5vcc
static void httpServerCallback(SoupServer* server, SoupMessage* message, const char* path, GHashTable*, SoupClientContext*, gpointer)
{
    if (message->method != SOUP_METHOD_GET) {
        soup_message_set_status(message, SOUP_STATUS_NOT_IMPLEMENTED);
        return;
    }

    if (g_str_equal(path, "/test-script")) {
        GOwnPtr<char> pathToFile(g_build_filename(Test::getResourcesDir().data(), "link-title.js", NULL));
        char* contents;
        gsize length;
        g_file_get_contents(pathToFile.get(), &contents, &length, 0);

        soup_message_body_append(message->response_body, SOUP_MEMORY_TAKE, contents, length);
        soup_message_set_status(message, SOUP_STATUS_OK);
        soup_message_body_complete(message->response_body);
    } else if (g_str_equal(path, "/test-image")) {
        GOwnPtr<char> pathToFile(g_build_filename(Test::getWebKit1TestResoucesDir().data(), "blank.ico", NULL));
        char* contents;
        gsize length;
        g_file_get_contents(pathToFile.get(), &contents, &length, 0);

        soup_message_body_append(message->response_body, SOUP_MEMORY_TAKE, contents, length);
        soup_message_set_status(message, SOUP_STATUS_OK);
        soup_message_body_complete(message->response_body);
    } else
        soup_message_set_status(message, SOUP_STATUS_NOT_FOUND);
}
示例#5
0
static void
write_next_chunk (SoupMessage *msg, gpointer user_data)
{
	PutTestData *ptd = user_data;

	debug_printf (2, "  writing chunk %d\n", ptd->next);

	if (ptd->next > 0 && ptd->chunks[ptd->next - 1]) {
		if (ptd->streaming) {
			debug_printf (1, "  error: next chunk requested before last one freed!\n");
			errors++;
		} else {
			debug_printf (0, "  ignoring bug in test case... FIXME!\n");
		}
	}

	if (ptd->next < G_N_ELEMENTS (ptd->chunks)) {
		soup_message_body_append_buffer (msg->request_body,
						 ptd->chunks[ptd->next]);
		soup_buffer_free (ptd->chunks[ptd->next]);
		ptd->next++;
	} else
		soup_message_body_complete (msg->request_body);
	soup_session_unpause_message (ptd->session, msg);
}
示例#6
0
/* For real request testing */
static void
server_callback(SoupServer* server, SoupMessage* msg,
                const char* path, GHashTable* query,
                SoupClientContext* context, gpointer data)
{
    if (msg->method != SOUP_METHOD_GET) {
        soup_message_set_status(msg, SOUP_STATUS_NOT_IMPLEMENTED);
        return;
    }

    soup_message_set_status(msg, SOUP_STATUS_OK);

    if (g_str_equal(path, "/test_loading_status") || g_str_equal(path, "/test_loading_status2"))
        soup_message_body_append(msg->response_body, SOUP_MEMORY_STATIC, HTML_STRING, strlen(HTML_STRING));
    else if (g_str_equal(path, "/test_load_error")) {
        soup_message_set_status(msg, SOUP_STATUS_CANT_CONNECT);
    } else if (g_str_equal(path, "/test_loading_cancelled")) {
        soup_message_headers_set_encoding(msg->response_headers, SOUP_ENCODING_CHUNKED);
        soup_message_body_append(msg->response_body, SOUP_MEMORY_STATIC, HTML_STRING, strlen(HTML_STRING));
        soup_server_unpause_message(server, msg);
        return;
    }

    soup_message_body_complete(msg->response_body);
}
示例#7
0
static void
serverCallback(SoupServer *server, SoupMessage *message, const char *path, GHashTable *query, SoupClientContext *context, void *data)
{
    if (message->method != SOUP_METHOD_GET) {
        soup_message_set_status(message, SOUP_STATUS_NOT_IMPLEMENTED);
        return;
    }

    soup_message_set_status(message, SOUP_STATUS_OK);

    char *contents;
    gsize length;
    if (g_str_equal(path, "/favicon.ico")) {
        GError *error = NULL;

        g_file_get_contents("blank.ico", &contents, &length, &error);
        g_assert(!error);
    } else {
        contents = g_strdup("<html><body>test</body></html>");
        length = strlen(contents);
    }

    soup_message_body_append(message->response_body, SOUP_MEMORY_TAKE, contents, length);
    soup_message_body_complete(message->response_body);
}
示例#8
0
static void
snra_server_connection_lost (SnraServerClient * client)
{
    if (client->fired_conn_lost)
        return;
    client->fired_conn_lost = TRUE;

    g_print ("Lost connection for client %u\n", client->conn_id);

    if (client->io) {
        g_source_remove (client->io_watch);
        g_io_channel_shutdown (client->io, TRUE, NULL);
        g_io_channel_unref (client->io);
        client->io = NULL;
    }

    if (client->type == SNRA_SERVER_CLIENT_CHUNKED ||
            client->type == SNRA_SERVER_CLIENT_SINGLE) {
        if (client->need_body_complete)
            soup_message_body_complete (client->event_pipe->response_body);
        client->need_body_complete = FALSE;
        soup_server_unpause_message (client->soup, client->event_pipe);
    }

    if (client->socket) {
        soup_socket_disconnect (client->socket);
        client->socket = NULL;
    }

    g_signal_emit (client, snra_server_client_signals[CONNECTION_LOST], 0, NULL);
}
示例#9
0
static void
korva_upnp_file_server_on_wrote_chunk (SoupMessage *msg,
                                       gpointer     user_data)
{
    ServeData *data = (ServeData *) user_data;
    int chunk_size;
    char *file_buffer;
    GError *error = NULL;
    gsize bytes_read;

    soup_server_pause_message (data->server, msg);

    chunk_size = MIN (data->end - data->start + 1, G_MAXUINT16 + 1);

    if (chunk_size <= 0) {
        soup_message_body_complete (msg->response_body);
        soup_server_unpause_message (data->server, msg);

        return;
    }

    file_buffer = g_malloc0 (chunk_size);
    g_input_stream_read_all (data->stream,
                             (void *) file_buffer,
                             chunk_size,
                             &bytes_read,
                             NULL,
                             &error);

    data->start += chunk_size;
    soup_message_body_append (msg->response_body, SOUP_MEMORY_TAKE, file_buffer, chunk_size);

    soup_server_unpause_message (data->server, msg);
}
示例#10
0
/* For real request testing */
static void
server_callback(SoupServer* server, SoupMessage* msg,
                 const char* path, GHashTable* query,
                 SoupClientContext* context, gpointer data)
{
    if (msg->method != SOUP_METHOD_GET) {
        soup_message_set_status(msg, SOUP_STATUS_NOT_IMPLEMENTED);
        return;
    }

    soup_message_set_status(msg, SOUP_STATUS_OK);

    if (g_str_equal(path, "/favicon.ico")) {
        char* contents;
        gsize length;
        GError* error = NULL;

        g_file_get_contents("blank.ico", &contents, &length, &error);
        g_assert(!error);

        soup_message_body_append(msg->response_body, SOUP_MEMORY_TAKE, contents, length);
    } else if (g_str_equal(path, "/bigdiv.html")) {
        char* contents = g_strdup("<html><body><div style=\"background-color: green; height: 1200px;\"></div></body></html>");
        soup_message_body_append(msg->response_body, SOUP_MEMORY_TAKE, contents, strlen(contents));
    } else if (g_str_equal(path, "/iframe.html")) {
        char* contents = g_strdup("<html><body><div style=\"background-color: green; height: 50px;\"></div><iframe src=\"bigdiv.html\"></iframe></body></html>");
        soup_message_body_append(msg->response_body, SOUP_MEMORY_TAKE, contents, strlen(contents));
    } else {
        char* contents = g_strdup("<html><body>test</body></html>");
        soup_message_body_append(msg->response_body, SOUP_MEMORY_TAKE, contents, strlen(contents));
    }

    soup_message_body_complete(msg->response_body);
}
void
dmap_write_next_chunk (SoupMessage * message, ChunkData * cd)
{
	gssize read_size;
	GError *error = NULL;
	gchar *chunk = g_malloc (DMAP_SHARE_CHUNK_SIZE);

	g_debug ("Trying to read %d bytes.", DMAP_SHARE_CHUNK_SIZE);
	read_size = g_input_stream_read (cd->stream,
					 chunk,
					 DMAP_SHARE_CHUNK_SIZE, NULL, &error);
	if (read_size > 0) {
		soup_message_body_append (message->response_body,
					  SOUP_MEMORY_TAKE, chunk, read_size);
		g_debug ("Read/wrote %d bytes.", read_size);
	} else {
		if (error != NULL) {
			g_warning ("Error reading from input stream: %s",
				   error->message);
			g_error_free (error);
		}
		g_free (chunk);
		g_debug ("Wrote 0 bytes, sending message complete.");
		soup_message_body_complete (message->response_body);
	}
	soup_server_unpause_message (cd->server, message);
}
示例#12
0
static void
snra_server_client_finalize (GObject * object)
{
    SnraServerClient *client = (SnraServerClient *) (object);

    if (client->disco_sig) {
        g_signal_handler_disconnect (client->event_pipe, client->disco_sig);
        client->disco_sig = 0;
    }
    if (client->net_event_sig) {
        g_signal_handler_disconnect (client->event_pipe, client->net_event_sig);
        client->net_event_sig = 0;
    }
    if (client->wrote_info_sig) {
        g_signal_handler_disconnect (client->event_pipe, client->wrote_info_sig);
        client->wrote_info_sig = 0;
    }

    if (client->need_body_complete) {
        soup_message_body_complete (client->event_pipe->response_body);
    }

    if (client->socket)
        soup_socket_disconnect (client->socket);

    g_free (client->host);

    g_free (client->in_buf);
    g_free (client->out_buf);

    G_OBJECT_CLASS (snra_server_client_parent_class)->finalize (object);
}
static void
gss_adaptive_dash_range_async_finish (GssTransaction * t, gpointer priv)
{
  GssAdaptiveQuery *query = priv;

  soup_message_body_complete (t->msg->response_body);
  soup_server_unpause_message (t->soupserver, t->msg);
  g_free (query);
}
示例#14
0
文件: TestSSL.cpp 项目: jiezh/h5vcc
static void httpsServerCallback(SoupServer* server, SoupMessage* message, const char* path, GHashTable*, SoupClientContext*, gpointer)
{
    if (message->method != SOUP_METHOD_GET) {
        soup_message_set_status(message, SOUP_STATUS_NOT_IMPLEMENTED);
        return;
    }

    if (g_str_equal(path, "/")) {
        soup_message_set_status(message, SOUP_STATUS_OK);
        soup_message_body_append(message->response_body, SOUP_MEMORY_STATIC, indexHTML, strlen(indexHTML));
        soup_message_body_complete(message->response_body);
    } else if (g_str_equal(path, "/insecure-content/")) {
        GOwnPtr<char> responseHTML(g_strdup_printf(insecureContentHTML, kHttpServer->getURIForPath("/test-script").data(), kHttpServer->getURIForPath("/test-image").data()));
        soup_message_body_append(message->response_body, SOUP_MEMORY_COPY, responseHTML.get(), strlen(responseHTML.get()));
        soup_message_set_status(message, SOUP_STATUS_OK);
        soup_message_body_complete(message->response_body);
    } else
        soup_message_set_status(message, SOUP_STATUS_NOT_FOUND);
}
示例#15
0
void
soup_soap_message_persist (SoupSoapMessage *msg)
{
	g_return_if_fail (SOUP_SOAP_IS_MESSAGE (msg));

	xmlChar *buffer;
	const gchar *contents;

	SoupSoapMessagePrivate *priv = msg->priv;

	xmlDocPtr doc = xmlNewDoc (BAD_CAST "1.0");


	xmlNodePtr envelope_node = xmlNewNode (NULL, BAD_CAST "Envelope");
	xmlSetNs (envelope_node,
	          xmlNewNs (envelope_node,
	                    BAD_CAST SOAP_ENV_NAMESPACE,
	                    BAD_CAST "SOAP-ENV"));
	xmlNewNs (envelope_node,
	          BAD_CAST XSD_NAMESPACE,
	          BAD_CAST "xsd");
	xmlNewNs (envelope_node,
	          BAD_CAST XSI_NAMESPACE,
	          BAD_CAST "xsi");
	xmlNewNs (envelope_node,
	          BAD_CAST SOAP_ENC_NAMESPACE,
	          BAD_CAST "SOAP-ENC");
	xmlSetProp (envelope_node,
	            BAD_CAST "SOAP-ENV:encodingStyle",
	            BAD_CAST SOAP_ENCODING_STYLE);
	xmlDocSetRootElement (doc, envelope_node);

	create_param_node (doc, SOUP_SOAP_PARAM (priv->header), envelope_node);

	xmlNodePtr body_node = xmlNewChild (envelope_node, NULL, BAD_CAST "Body", NULL);
	create_param_node (doc, SOUP_SOAP_PARAM (priv->body), body_node);


	xmlDocDumpFormatMemoryEnc (doc, &buffer, NULL, "UTF-8", 0);

	contents = (gchar *) buffer;
	soup_message_body_truncate (priv->message_body);
	soup_message_body_append (priv->message_body, SOUP_MEMORY_COPY,
	                          contents, strlen (contents));
	soup_message_body_complete (priv->message_body);

	xmlFree (buffer);


	xmlFreeDoc (doc);


	soup_message_headers_set_content_type (priv->message_headers,
	                                       "text/xml", NULL);
}
示例#16
0
/* For real request testing */
static void
server_callback(SoupServer *server, SoupMessage *msg,
                 const char *path, GHashTable *query,
                 SoupClientContext *context, gpointer data)
{
    if (msg->method != SOUP_METHOD_GET) {
        soup_message_set_status(msg, SOUP_STATUS_NOT_IMPLEMENTED);
        return;
    }

    soup_message_set_status(msg, SOUP_STATUS_OK);

    /* PDF */
    if (g_str_equal(path, "/pdf")) {
        char* contents;
        gsize length;
        GError* error = NULL;

        g_file_get_contents("test.pdf", &contents, &length, &error);
        g_assert(!error);

        soup_message_body_append(msg->response_body, SOUP_MEMORY_TAKE, contents, length);
    } else if (g_str_equal(path, "/html")) {
        char* contents;
        gsize length;
        GError* error = NULL;

        g_file_get_contents("test.html", &contents, &length, &error);
        g_assert(!error);

        soup_message_body_append(msg->response_body, SOUP_MEMORY_TAKE, contents, length);
    } else if (g_str_equal(path, "/text")) {
        char* contents;
        gsize length;
        GError* error = NULL;

        soup_message_headers_append(msg->response_headers, "Content-Disposition", "attachment; filename=test.txt");

        g_file_get_contents("test.txt", &contents, &length, &error);
        g_assert(!error);

        soup_message_body_append(msg->response_body, SOUP_MEMORY_TAKE, contents, length);
    } else if (g_str_equal(path, "/ogg")) {
        char* contents;
        gsize length;
        GError* error = NULL;

        g_file_get_contents("test.ogg", &contents, &length, &error);
        g_assert(!error);

        soup_message_body_append(msg->response_body, SOUP_MEMORY_TAKE, contents, length);
    }

    soup_message_body_complete(msg->response_body);
}
示例#17
0
文件: message.c 项目: p3ck/restraint
void
restraint_close_message (gpointer msg_data)
{
    ClientData *client_data = (ClientData *) msg_data;
    g_print ("[%p] Closing client\n", client_data->client_msg);
    soup_message_body_append (client_data->client_msg->response_body,
                              SOUP_MEMORY_STATIC,
                              "\r\n--cut-here--\r\n",
                              16);
    soup_message_body_complete (client_data->client_msg->response_body);
    soup_server_unpause_message (client_data->server, client_data->client_msg);
}
示例#18
0
static void
finish_msg (SoupSession *session, SoupMessage *msg2, gpointer data)
{
	SoupMessage *msg = data;

	g_print ("[%p]   done\n\n", msg);
	g_signal_handlers_disconnect_by_func (msg, client_msg_failed, msg2);

	soup_message_body_complete (msg->response_body);
	soup_server_unpause_message (server, msg);
	g_object_unref (msg);
}
示例#19
0
static void serverCallback(SoupServer* server, SoupMessage* message, const char* path, GHashTable*, SoupClientContext*, gpointer)
{
    if (message->method != SOUP_METHOD_GET) {
        soup_message_set_status(message, SOUP_STATUS_NOT_IMPLEMENTED);
        return;
    }

    soup_message_set_status(message, SOUP_STATUS_OK);
    const char* userAgent = soup_message_headers_get_one(message->request_headers, "User-Agent");
    soup_message_body_append(message->response_body, SOUP_MEMORY_COPY, userAgent, strlen(userAgent));
    soup_message_body_complete(message->response_body);
}
示例#20
0
static gboolean
add_body_chunk (gpointer data)
{
	SlowData *sd = data;

	soup_message_body_append (sd->msg->response_body,
				  SOUP_MEMORY_STATIC, "OK\r\n", 4);
	soup_message_body_complete (sd->msg->response_body);
	soup_server_unpause_message (sd->server, sd->msg);
	g_object_unref (sd->msg);

	return FALSE;
}
示例#21
0
static void serverCallback(SoupServer* server, SoupMessage* message, const char* path, GHashTable*, SoupClientContext*, gpointer)
{
    if (message->method != SOUP_METHOD_GET) {
        soup_message_set_status(message, SOUP_STATUS_NOT_IMPLEMENTED);
        return;
    }

    if (g_str_equal(path, "/native")) {
        soup_message_set_status(message, SOUP_STATUS_OK);
        soup_message_headers_append(message->response_headers, "Content-Type", "text/xml");
        static const char* nativeXML = "<root xmlns:foo='http://www.example.org'><foo:child>SUCCESS</foo:child></root>";
        soup_message_body_append(message->response_body, SOUP_MEMORY_STATIC, nativeXML, strlen(nativeXML));
        soup_message_body_complete(message->response_body);
    } else if (g_str_equal(path, "/custom")) {
        soup_message_set_status(message, SOUP_STATUS_OK);
        soup_message_headers_append(message->response_headers, "Content-Type", "text/xml");
        static const char* customXML = "<root xmlns='http://www.example.com'><child>SUCCESS</child></root>";
        soup_message_body_append(message->response_body, SOUP_MEMORY_STATIC, customXML, strlen(customXML));
        soup_message_body_complete(message->response_body);
    } else
        soup_message_set_status(message, SOUP_STATUS_NOT_FOUND);
}
示例#22
0
static void serverCallback(SoupServer* server, SoupMessage* msg, const char* path, GHashTable* query, SoupClientContext* context, gpointer data)
{
    if (msg->method != SOUP_METHOD_GET) {
        soup_message_set_status(msg, SOUP_STATUS_NOT_IMPLEMENTED);
        return;
    }

    soup_message_set_status(msg, SOUP_STATUS_OK);

    char* body = g_strdup_printf("<html><title>%s</title><body>%s</body></html>", path + 1, path + 1);
    soup_message_body_append(msg->response_body, SOUP_MEMORY_TAKE, body, strlen(body));

    soup_message_body_complete(msg->response_body);
}
示例#23
0
static void finish_msg(SoupSession *session, SoupMessage *new_msg, gpointer data)
{

	SoupMessage *to = ((struct destination_info *) data)->msg;
	SoupServer *server = ((struct destination_info *) data)->server;

	g_print("[%p] done\n\n", to);

	soup_message_body_complete(to->response_body);

	soup_server_unpause_message(server, to);
	free(data);
	g_object_unref(to);
}
static void serverCallback(SoupServer* server, SoupMessage* message, const char* path, GHashTable*, SoupClientContext*, gpointer)
{
    if (message->method != SOUP_METHOD_GET) {
        soup_message_set_status(message, SOUP_STATUS_NOT_IMPLEMENTED);
        return;
    }

    if (g_str_equal(path, "/")) {
        static const char* responseString = "<html><body>Testing!</body></html>";
        soup_message_set_status(message, SOUP_STATUS_OK);
        soup_message_body_append(message->response_body, SOUP_MEMORY_STATIC, responseString, strlen(responseString));
        soup_message_body_complete(message->response_body);
    } else
        soup_message_set_status(message, SOUP_STATUS_NOT_FOUND);
}
示例#25
0
static void serverCallback(SoupServer* server, SoupMessage* message, const char* path, GHashTable*, SoupClientContext*, gpointer)
{
    if (message->method != SOUP_METHOD_GET) {
        soup_message_set_status(message, SOUP_STATUS_NOT_IMPLEMENTED);
        return;
    }

    if (g_str_equal(path, "/")) {
        const char* acceptLanguage = soup_message_headers_get_one(message->request_headers, "Accept-Language");
        soup_message_set_status(message, SOUP_STATUS_OK);
        soup_message_body_append(message->response_body, SOUP_MEMORY_COPY, acceptLanguage, strlen(acceptLanguage));
        soup_message_body_complete(message->response_body);
    } else
        soup_message_set_status(message, SOUP_STATUS_NOT_FOUND);
}
示例#26
0
static void
server_callback (SoupServer *server,
                 SoupMessage *msg,
                 const char *path,
                 GHashTable *query,
                 SoupClientContext *context,
                 gpointer data)
{
  soup_message_set_status (msg, SOUP_STATUS_OK);

  if (g_str_equal (path, "/cancelled"))
    soup_message_set_status (msg, SOUP_STATUS_CANT_CONNECT);

  soup_message_body_append (msg->response_body, SOUP_MEMORY_STATIC,
                            HTML_STRING, strlen (HTML_STRING));

  soup_message_body_complete (msg->response_body);
}
示例#27
0
static void
vod_wrote_chunk (SoupMessage * msg, GssVOD * vod)
{
  char *chunk;
  int len;

  chunk = g_malloc (SIZE);
  len = read (vod->fd, chunk, 65536);
  if (len < 0) {
    GST_ERROR ("read error");
  }
  if (len == 0) {
    soup_message_body_complete (msg->response_body);
    return;
  }

  soup_message_body_append (msg->response_body, SOUP_MEMORY_TAKE, chunk, len);
}
示例#28
0
static
void
test_http_callback(
    SoupServer* server,
    SoupMessage* msg,
    const char* path,
    GHashTable* query,
    SoupClientContext* context,
    gpointer data)
{
    char* uri = soup_uri_to_string(soup_message_get_uri (msg), FALSE);
    MMS_VERBOSE("%s %s HTTP/1.%d", msg->method, uri,
        soup_message_get_http_version(msg));
    g_free(uri);
    if (msg->method == SOUP_METHOD_CONNECT) {
        soup_message_set_status(msg, SOUP_STATUS_NOT_IMPLEMENTED);
    } else {
        TestHttp* http = data;
        if (msg->request_body->length) {
            SoupBuffer* request = soup_message_body_flatten(msg->request_body);
            if (http->req_bytes) g_bytes_unref(http->req_bytes);
            http->req_bytes = g_bytes_new_with_free_func(request->data,
                request->length, (GDestroyNotify)soup_buffer_free, request);
        }
        soup_message_set_status(msg, http->resp_status);
        soup_message_headers_set_content_type(msg->response_headers,
            http->resp_content_type ? http->resp_content_type : "text/plain",
            NULL);
        soup_message_headers_append(msg->response_headers,
            "Accept-Ranges", "bytes");
        soup_message_headers_append(msg->response_headers,
            "Connection", "close");
        if (http->resp_file) {
            soup_message_headers_set_content_length(msg->response_headers,
                g_mapped_file_get_length(http->resp_file));
            soup_message_body_append(msg->response_body, SOUP_MEMORY_TEMPORARY,
                g_mapped_file_get_contents(http->resp_file),
                g_mapped_file_get_length(http->resp_file));
        } else {
            soup_message_headers_set_content_length(msg->response_headers, 0);
        }
    }
    soup_message_body_complete(msg->request_body);
}
示例#29
0
static void
server_callback (SoupServer *server, SoupMessage *msg,
                 const char *path, GHashTable *query,
                 SoupClientContext *context, gpointer data)
{
    if (msg->method != SOUP_METHOD_GET) {
        soup_message_set_status (msg, SOUP_STATUS_NOT_IMPLEMENTED);
        return;
    }

    soup_message_set_status (msg, SOUP_STATUS_OK);

    soup_message_headers_append (msg->response_headers,
                                 "Content-Type", "multipart/x-mixed-replace; boundary=cut-here");

    soup_message_body_append (msg->response_body,
                              SOUP_MEMORY_STATIC,
                              payload,
                              strlen (payload));

    soup_message_body_complete (msg->response_body);
}
示例#30
0
/* For real request testing */
static void
server_callback (SoupServer *server, SoupMessage *msg,
                 const char *path, GHashTable *query,
                 SoupClientContext *context, gpointer data)
{
    if (msg->method != SOUP_METHOD_GET) {
        soup_message_set_status (msg, SOUP_STATUS_NOT_IMPLEMENTED);
        return;
    }

    soup_message_set_status (msg, SOUP_STATUS_OK);

    /* Redirect */
    if (g_str_equal (path, "/")) {
        soup_message_set_status (msg, SOUP_STATUS_MOVED_PERMANENTLY);

        soup_message_headers_append (msg->response_headers,
                                     "Location", "/index.html");
    } else if (g_str_equal (path, "/index.html")) {
        soup_message_body_append (msg->response_body,
                                  SOUP_MEMORY_COPY,
                                  INDEX_HTML,
                                  strlen (INDEX_HTML));
    } else if (g_str_equal (path, "/main.html")) {
        soup_message_body_append (msg->response_body,
                                  SOUP_MEMORY_COPY,
                                  MAIN_HTML,
                                  strlen (MAIN_HTML));
    } else if (g_str_equal (path, "/javascript.js")) {
        soup_message_body_append (msg->response_body,
                                  SOUP_MEMORY_COPY,
                                  JAVASCRIPT,
                                  strlen (JAVASCRIPT));
    }


    soup_message_body_complete (msg->response_body);
}