mirror of https://github.com/ipxe/ipxe.git
[http] Use POST method only if the form parameter list is non-empty
An attempt to use an existent but empty form parameter list will currently result in an invalid POST request since the Content-Length header will be missing. Fix by using GET instead of POST if the form parameter list is empty. This is a non-breaking change (since the current behaviour produces an invalid request), and simplifies the imminent generalisation of the parameter list concept to handle both header and form parameters. Signed-off-by: Michael Brown <mcb30@ipxe.org>efivars
parent
04e60a278a
commit
60531ff6e2
|
|
@ -1904,34 +1904,31 @@ static size_t http_params ( struct parameters *params, char *buf, size_t len ) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Open HTTP transaction for simple GET URI
|
* Open HTTP transaction for simple URI
|
||||||
*
|
*
|
||||||
* @v xfer Data transfer interface
|
* @v xfer Data transfer interface
|
||||||
* @v uri Request URI
|
* @v uri Request URI
|
||||||
* @ret rc Return status code
|
* @ret rc Return status code
|
||||||
*/
|
*/
|
||||||
static int http_open_get_uri ( struct interface *xfer, struct uri *uri ) {
|
int http_open_uri ( struct interface *xfer, struct uri *uri ) {
|
||||||
|
|
||||||
return http_open ( xfer, &http_get, uri, NULL, NULL );
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Open HTTP transaction for simple POST URI
|
|
||||||
*
|
|
||||||
* @v xfer Data transfer interface
|
|
||||||
* @v uri Request URI
|
|
||||||
* @ret rc Return status code
|
|
||||||
*/
|
|
||||||
static int http_open_post_uri ( struct interface *xfer, struct uri *uri ) {
|
|
||||||
struct parameters *params = uri->params;
|
struct parameters *params = uri->params;
|
||||||
struct http_request_content content;
|
struct http_request_content content;
|
||||||
|
struct http_method *method;
|
||||||
|
const char *type;
|
||||||
void *data;
|
void *data;
|
||||||
size_t len;
|
size_t len;
|
||||||
size_t check_len;
|
size_t check_len;
|
||||||
int rc;
|
int rc;
|
||||||
|
|
||||||
/* Calculate length of parameter list */
|
/* Calculate length of parameter list, if any */
|
||||||
len = http_params ( params, NULL, 0 );
|
len = ( params ? http_params ( params, NULL, 0 ) : 0 );
|
||||||
|
|
||||||
|
/* Use POST if and only if there are parameters */
|
||||||
|
if ( len ) {
|
||||||
|
|
||||||
|
/* Use POST */
|
||||||
|
method = &http_post;
|
||||||
|
type = "application/x-www-form-urlencoded";
|
||||||
|
|
||||||
/* Allocate temporary parameter list */
|
/* Allocate temporary parameter list */
|
||||||
data = zalloc ( len + 1 /* NUL */ );
|
data = zalloc ( len + 1 /* NUL */ );
|
||||||
|
|
@ -1944,13 +1941,21 @@ static int http_open_post_uri ( struct interface *xfer, struct uri *uri ) {
|
||||||
check_len = http_params ( params, data, ( len + 1 /* NUL */ ) );
|
check_len = http_params ( params, data, ( len + 1 /* NUL */ ) );
|
||||||
assert ( check_len == len );
|
assert ( check_len == len );
|
||||||
|
|
||||||
|
} else {
|
||||||
|
|
||||||
|
/* Use GET */
|
||||||
|
method = &http_get;
|
||||||
|
type = NULL;
|
||||||
|
data = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
/* Construct request content */
|
/* Construct request content */
|
||||||
content.type = "application/x-www-form-urlencoded";
|
content.type = type;
|
||||||
content.data = data;
|
content.data = data;
|
||||||
content.len = len;
|
content.len = len;
|
||||||
|
|
||||||
/* Open HTTP transaction */
|
/* Open HTTP transaction */
|
||||||
if ( ( rc = http_open ( xfer, &http_post, uri, NULL, &content ) ) != 0 )
|
if ( ( rc = http_open ( xfer, method, uri, NULL, &content ) ) != 0 )
|
||||||
goto err_open;
|
goto err_open;
|
||||||
|
|
||||||
err_open:
|
err_open:
|
||||||
|
|
@ -1959,23 +1964,6 @@ static int http_open_post_uri ( struct interface *xfer, struct uri *uri ) {
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Open HTTP transaction for simple URI
|
|
||||||
*
|
|
||||||
* @v xfer Data transfer interface
|
|
||||||
* @v uri Request URI
|
|
||||||
* @ret rc Return status code
|
|
||||||
*/
|
|
||||||
int http_open_uri ( struct interface *xfer, struct uri *uri ) {
|
|
||||||
|
|
||||||
/* Open GET/POST URI as applicable */
|
|
||||||
if ( uri->params ) {
|
|
||||||
return http_open_post_uri ( xfer, uri );
|
|
||||||
} else {
|
|
||||||
return http_open_get_uri ( xfer, uri );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Drag in HTTP extensions */
|
/* Drag in HTTP extensions */
|
||||||
REQUIRING_SYMBOL ( http_open );
|
REQUIRING_SYMBOL ( http_open );
|
||||||
REQUIRE_OBJECT ( config_http );
|
REQUIRE_OBJECT ( config_http );
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue