* @method: the HTTP method for the created request
* @uri_string: the destination endpoint (as a string)
*
- * Creates a new empty #SoupMessage, which will connect to @uri
+ * Creates a new empty #SoupMessage, which will connect to @uri.
+ *
+ * @uri should not include a fragment identifier (ie, a "#" followed
+ * by an HTML anchor name, etc); fragments are not meaningful at the
+ * HTTP level.
*
* Return value: the new #SoupMessage (or %NULL if @uri could not
* be parsed).
*
* Creates a new empty #SoupMessage, which will connect to @uri
*
+ * @uri should not include a fragment identifier; fragments are not
+ * meaningful at the HTTP level.
+ *
* Return value: the new #SoupMessage
*/
SoupMessage *
* Sets @msg's URI to @uri. If @msg has already been sent and you want
* to re-send it with the new URI, you need to call
* soup_session_requeue_message().
+ *
+ * @uri should not include a fragment identifier.
**/
void
soup_message_set_uri (SoupMessage *msg, SoupURI *uri)
}
priv->uri = soup_uri_copy (uri);
+ if (priv->uri && priv->uri->fragment) {
+ char *uristr = soup_uri_to_string (priv->uri, FALSE);
+ g_warning ("soup_message_set_uri: stripping fragment identifier from URI '%s'",
+ uristr);
+ g_free (uristr);
+ soup_uri_set_fragment (priv->uri, NULL);
+ }
+
g_object_notify (G_OBJECT (msg), SOUP_MESSAGE_URI);
}
return;
}
+ /* URI fragments are also not allowed in Location, but again,
+ * some sites do this. Strip it to keep soup_message_set_uri()
+ * from warning about it. (If the application wants to obey
+ * the fragment anyway it can reparse Location itself.)
+ */
+ soup_uri_set_fragment (new_uri, NULL);
+
soup_message_set_uri (msg, new_uri);
soup_uri_free (new_uri);
{ { { "POST", "/307", 307 },
{ NULL } }, 307 },
+ /* Test behavior with Location header containing URI fragment */
+ { { { "GET", "/bad-with-fragment", 302 },
+ { "GET", "/", 200 },
+ { NULL } }, 200 },
+
/* Test behavior with recoverably-bad Location header */
{ { { "GET", "/bad", 302 },
{ "GET", "/bad%20with%20spaces", 200 },
soup_message_headers_replace (msg->response_headers,
"Location",
"about:blank");
+ } else if (!strcmp (path, "/bad-with-fragment")) {
+ soup_message_set_status (msg, SOUP_STATUS_FOUND);
+ soup_message_headers_replace (msg->response_headers,
+ "Location",
+ "/#fragment");
} else if (!strcmp (path, "/bad with spaces"))
soup_message_set_status (msg, SOUP_STATUS_OK);
else