Skip to content

Commit

Permalink
rgw: If the client sends a Connection: close header respond accordingly.
Browse files Browse the repository at this point in the history
HTTP/1.1 assumes Keep-Alive by default, but if a Connection: close header is send
the server should respond with it as well.

This makes the client close the connection after the request.

Fixes: #12298
(cherry picked from commit 79197d3)
  • Loading branch information
wido authored and smithfarm committed Jul 19, 2015
1 parent 45beb86 commit 2357b6c
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/rgw/rgw_civetweb.cc
Expand Up @@ -23,7 +23,7 @@ int RGWMongoose::write_data(const char *buf, int len)
}

RGWMongoose::RGWMongoose(mg_connection *_conn, int _port) : conn(_conn), port(_port), header_done(false), sent_header(false), has_content_length(false),
explicit_keepalive(false)
explicit_keepalive(false), explicit_conn_close(false)
{
}

Expand Down Expand Up @@ -88,6 +88,7 @@ void RGWMongoose::init_env(CephContext *cct)

if (strcasecmp(header->name, "connection") == 0) {
explicit_keepalive = (strcasecmp(header->value, "keep-alive") == 0);
explicit_conn_close = (strcasecmp(header->value, "close") == 0);
}

int len = strlen(header->name) + 5; /* HTTP_ prepended */
Expand Down Expand Up @@ -157,6 +158,8 @@ int RGWMongoose::complete_header()

if (explicit_keepalive)
header_data.append("Connection: Keep-Alive\r\n");
else if (explicit_conn_close)
header_data.append("Connection: close\r\n");

header_data.append("\r\n");

Expand Down
1 change: 1 addition & 0 deletions src/rgw/rgw_civetweb.h
Expand Up @@ -23,6 +23,7 @@ class RGWMongoose : public RGWClientIO
bool sent_header;
bool has_content_length;
bool explicit_keepalive;
bool explicit_conn_close;

public:
void init_env(CephContext *cct);
Expand Down

0 comments on commit 2357b6c

Please sign in to comment.