mirror of
https://github.com/ipxe/ipxe
synced 2026-10-07 15:05:42 +03:00
[http] Include a zero request content length when applicable
We currently send a Content-Length request header only when the content length is non-zero. This breaks some use cases for a PUT request, such as uploading a zero-length file to AWS S3. Fix by choosing whether or not to include a Content-Length request header based on the request method. Signed-off-by: Michael Brown <mcb30@ipxe.org>
This commit is contained in:
@@ -100,8 +100,13 @@ struct http_connection {
|
||||
struct http_method {
|
||||
/** Method name (e.g. "GET" or "POST") */
|
||||
const char *name;
|
||||
/** Flags */
|
||||
unsigned int flags;
|
||||
};
|
||||
|
||||
/** HTTP method has a request body */
|
||||
#define HTTP_FL_REQ_BODY 0x0001
|
||||
|
||||
/** HTTP method table */
|
||||
#define HTTP_METHODS __table ( struct http_method, "http_methods" )
|
||||
|
||||
|
||||
+10
-2
@@ -138,21 +138,25 @@ static struct http_transfer_encoding http_transfer_identity;
|
||||
/** HTTP HEAD method */
|
||||
struct http_method http_head __http_method = {
|
||||
.name = "HEAD",
|
||||
.flags = 0,
|
||||
};
|
||||
|
||||
/** HTTP GET method */
|
||||
struct http_method http_get __http_method = {
|
||||
.name = "GET",
|
||||
.flags = 0,
|
||||
};
|
||||
|
||||
/** HTTP POST method */
|
||||
struct http_method http_post __http_method = {
|
||||
.name = "POST",
|
||||
.flags = HTTP_FL_REQ_BODY,
|
||||
};
|
||||
|
||||
/** HTTP PUT method */
|
||||
struct http_method http_put __http_method = {
|
||||
.name = "PUT",
|
||||
.flags = HTTP_FL_REQ_BODY,
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -1095,11 +1099,15 @@ static int http_format_content_length ( struct http_transaction *http,
|
||||
char *buf, size_t len ) {
|
||||
|
||||
/* Construct content length, if applicable */
|
||||
if ( http->request.content.len ) {
|
||||
if ( http->request.method->flags & HTTP_FL_REQ_BODY ) {
|
||||
return snprintf ( buf, len, "%zd", http->request.content.len );
|
||||
} else {
|
||||
} else if ( http->request.content.len == 0 ) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
DBGC ( http, "HTTP %p cannot %s with a request body\n",
|
||||
http, http->request.method->name );
|
||||
return -ENOTSUP;
|
||||
}
|
||||
|
||||
/** HTTP "Content-Length" header */
|
||||
|
||||
Reference in New Issue
Block a user