Пример #1
0
static void
redirect_handler (SoupMessage *msg, gpointer user_data)
{
	if (SOUP_STATUS_IS_REDIRECTION (msg->status_code)) {
		CallbackInfo *info = user_data;
		SoupURI *new_uri;
		const gchar *new_loc;

		new_loc = soup_message_headers_get (msg->response_headers, "Location");
		if (!new_loc)
			return;

		info->reset=1;

		new_uri = soup_uri_new_with_base (soup_message_get_uri (msg), new_loc);
		if (!new_uri) {
			soup_message_set_status_full (msg,
				SOUP_STATUS_MALFORMED,
				"Invalid Redirect URL");
			return;
		}

		soup_message_set_uri (msg, new_uri);
		soup_session_requeue_message (info->ss, msg);

		soup_uri_free (new_uri);
	}
}
Пример #2
0
static void
soup_session_cb (SoupSession *session,
                 SoupMessage *msg,
                 gpointer     user_data)
{
  DQTask *task = user_data;

  if (SOUP_STATUS_IS_REDIRECTION (msg->status_code))
    {
      const char *header =
        soup_message_headers_get_one (msg->response_headers, "Location");

      if (header)
        {
          SoupURI *uri;

          uri = soup_uri_new_with_base (soup_message_get_uri (msg), header);
          soup_message_set_uri (msg, uri);
          soup_uri_free (uri);

          soup_session_requeue_message (session, msg);

          return;
        }
    }
  else if (SOUP_STATUS_IS_SUCCESSFUL (msg->status_code))
    {
      void *cache;

      task->any.callback (task->any.queue, task->any.uri,
                          msg->response_body->data,
                          msg->response_body->length,
                          NULL,
                          task->any.userdata);

      /* add the contents to the cache */
      cache = g_memdup (msg->response_body->data, msg->response_body->length);
      mex_download_queue_cache_insert (task->any.queue, task->any.uri, cache,
                                       msg->response_body->length);

    }
  else if (msg->status_code != SOUP_STATUS_CANCELLED)
    {
      /* FIXME: Also create an error on failure */
      task->any.callback (task->any.queue, task->any.uri,
                          NULL, 0, NULL,
                          task->any.userdata);
    }

  /* The message is unref'd by the session */
  task->soup.message = NULL;

  mex_download_queue_free (task);
}
Пример #3
0
static void
proxy_auth_got_body (SoupMessage *msg, gpointer manager)
{
	SoupAuthManagerPrivate *priv = SOUP_AUTH_MANAGER (manager)->priv;
	SoupAuth *auth;

	g_mutex_lock (&priv->lock);
	auth = priv->proxy_auth;

	if (auth && soup_auth_is_ready (auth, msg))
		soup_session_requeue_message (priv->session, msg);
	g_mutex_unlock (&priv->lock);
}
Пример #4
0
/**
 * Check if the host is known and switch the URI scheme to https.
 */
static void request_queued(SoupSessionFeature *feature,
    SoupSession *session, SoupMessage *msg)
{
    SoupURI *uri = soup_message_get_uri(msg);
    HSTSProvider *provider = HSTS_PROVIDER(feature);

    /* only look for HSTS headers sent over https RFC 6797 7.2*/
    if (uri->scheme == SOUP_URI_SCHEME_HTTPS) {
        soup_message_add_header_handler(
            msg, "got-headers", HSTS_HEADER_NAME, G_CALLBACK(process_hsts_header), feature
        );
    } else if (should_secure_host(provider, uri->host)) {
        /* the ports is set by soup uri if scheme is changed */
        soup_uri_set_scheme(uri, SOUP_URI_SCHEME_HTTPS);
        soup_session_requeue_message(session, msg);
    }
}
Пример #5
0
static void
auth_got_body (SoupMessage *msg, gpointer manager)
{
	SoupAuthManagerPrivate *priv = SOUP_AUTH_MANAGER (manager)->priv;
	SoupAuth *auth;

	g_mutex_lock (&priv->lock);
	auth = lookup_auth (priv, msg);
	if (auth && soup_auth_is_ready (auth, msg)) {
		if (SOUP_IS_CONNECTION_AUTH (auth)) {
			SoupMessageFlags flags;

			flags = soup_message_get_flags (msg);
			soup_message_set_flags (msg, flags & ~SOUP_MESSAGE_NEW_CONNECTION);
		}

		soup_session_requeue_message (priv->session, msg);
	}
	g_mutex_unlock (&priv->lock);
}
Пример #6
0
static void
redirect_handler (SoupMessage *msg, gpointer user_data)
{
	SoupSession *session = user_data;
	const char *new_loc;
	SoupURI *new_uri;

	new_loc = soup_message_headers_get_one (msg->response_headers,
						"Location");
	g_return_if_fail (new_loc != NULL);

	if (msg->status_code == SOUP_STATUS_SEE_OTHER ||
	    (msg->status_code == SOUP_STATUS_FOUND &&
	     !SOUP_METHOD_IS_SAFE (msg->method))) {
		/* Redirect using a GET */
		g_object_set (msg,
			      SOUP_MESSAGE_METHOD, SOUP_METHOD_GET,
			      NULL);
		soup_message_set_request (msg, NULL,
					  SOUP_MEMORY_STATIC, NULL, 0);
		soup_message_headers_set_encoding (msg->request_headers,
						   SOUP_ENCODING_NONE);
	} else if (msg->status_code == SOUP_STATUS_MOVED_PERMANENTLY ||
		   msg->status_code == SOUP_STATUS_TEMPORARY_REDIRECT ||
		   msg->status_code == SOUP_STATUS_FOUND) {
		/* Don't redirect non-safe methods */
		if (!SOUP_METHOD_IS_SAFE (msg->method))
			return;
	} else {
		/* Three possibilities:
		 *
		 *   1) This was a non-3xx response that happened to
		 *      have a "Location" header
		 *   2) It's a non-redirecty 3xx response (300, 304,
		 *      305, 306)
		 *   3) It's some newly-defined 3xx response (308+)
		 *
		 * We ignore all of these cases. In the first two,
		 * redirecting would be explicitly wrong, and in the
		 * last case, we have no clue if the 3xx response is
		 * supposed to be redirecty or non-redirecty. Plus,
		 * 2616 says unrecognized status codes should be
		 * treated as the equivalent to the x00 code, and we
		 * don't redirect on 300, so therefore we shouldn't
		 * redirect on 308+ either.
		 */
		return;
	}

	/* Location is supposed to be an absolute URI, but some sites
	 * are lame, so we use soup_uri_new_with_base().
	 */
	new_uri = soup_uri_new_with_base (soup_message_get_uri (msg), new_loc);
	if (!new_uri) {
		soup_message_set_status_full (msg,
					      SOUP_STATUS_MALFORMED,
					      "Invalid Redirect URL");
		return;
	}

	soup_message_set_uri (msg, new_uri);
	soup_uri_free (new_uri);

	soup_session_requeue_message (session, msg);
}