output/httpd: support HEAD requests
This commit is contained in:
parent
610bef9ff5
commit
e17da71a70
1
NEWS
1
NEWS
|
@ -28,6 +28,7 @@ ver 0.18 (2012/??/??)
|
||||||
- new option "tags" may be used to disable sending tags to output
|
- new option "tags" may be used to disable sending tags to output
|
||||||
- alsa: workaround for noise after manual song change
|
- alsa: workaround for noise after manual song change
|
||||||
- ffado: remove broken plugin
|
- ffado: remove broken plugin
|
||||||
|
- httpd: support HEAD requests
|
||||||
- mvp: remove obsolete plugin
|
- mvp: remove obsolete plugin
|
||||||
* improved decoder/output error reporting
|
* improved decoder/output error reporting
|
||||||
* eliminate timer wakeup on idle MPD
|
* eliminate timer wakeup on idle MPD
|
||||||
|
|
|
@ -66,7 +66,8 @@ HttpdClient::BeginResponse()
|
||||||
state = RESPONSE;
|
state = RESPONSE;
|
||||||
current_page = nullptr;
|
current_page = nullptr;
|
||||||
|
|
||||||
httpd->SendHeader(*this);
|
if (!head_method)
|
||||||
|
httpd->SendHeader(*this);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -78,16 +79,25 @@ HttpdClient::HandleLine(const char *line)
|
||||||
assert(state != RESPONSE);
|
assert(state != RESPONSE);
|
||||||
|
|
||||||
if (state == REQUEST) {
|
if (state == REQUEST) {
|
||||||
if (memcmp(line, "GET /", 5) != 0) {
|
if (memcmp(line, "HEAD /", 6) == 0) {
|
||||||
|
line += 6;
|
||||||
|
head_method = true;
|
||||||
|
} else if (memcmp(line, "GET /", 5) == 0) {
|
||||||
|
line += 5;
|
||||||
|
} else {
|
||||||
/* only GET is supported */
|
/* only GET is supported */
|
||||||
LogWarning(httpd_output_domain,
|
LogWarning(httpd_output_domain,
|
||||||
"malformed request line from client");
|
"malformed request line from client");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
line = strchr(line + 5, ' ');
|
line = strchr(line, ' ');
|
||||||
if (line == nullptr || memcmp(line + 1, "HTTP/", 5) != 0) {
|
if (line == nullptr || memcmp(line + 1, "HTTP/", 5) != 0) {
|
||||||
/* HTTP/0.9 without request headers */
|
/* HTTP/0.9 without request headers */
|
||||||
|
|
||||||
|
if (head_method)
|
||||||
|
return false;
|
||||||
|
|
||||||
BeginResponse();
|
BeginResponse();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -98,6 +108,7 @@ HttpdClient::HandleLine(const char *line)
|
||||||
} else {
|
} else {
|
||||||
if (*line == 0) {
|
if (*line == 0) {
|
||||||
/* empty line: request is finished */
|
/* empty line: request is finished */
|
||||||
|
|
||||||
BeginResponse();
|
BeginResponse();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -185,6 +196,7 @@ HttpdClient::HttpdClient(HttpdOutput *_httpd, int _fd, EventLoop &_loop,
|
||||||
:BufferedSocket(_fd, _loop),
|
:BufferedSocket(_fd, _loop),
|
||||||
httpd(_httpd),
|
httpd(_httpd),
|
||||||
state(REQUEST),
|
state(REQUEST),
|
||||||
|
head_method(false),
|
||||||
dlna_streaming_requested(false),
|
dlna_streaming_requested(false),
|
||||||
metadata_supported(_metadata_supported),
|
metadata_supported(_metadata_supported),
|
||||||
metadata_requested(false), metadata_sent(true),
|
metadata_requested(false), metadata_sent(true),
|
||||||
|
@ -427,8 +439,15 @@ HttpdClient::OnSocketInput(void *data, size_t length)
|
||||||
return InputResult::CLOSED;
|
return InputResult::CLOSED;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (state == RESPONSE && !SendResponse())
|
if (state == RESPONSE) {
|
||||||
return InputResult::CLOSED;
|
if (!SendResponse())
|
||||||
|
return InputResult::CLOSED;
|
||||||
|
|
||||||
|
if (head_method) {
|
||||||
|
LockClose();
|
||||||
|
return InputResult::CLOSED;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return InputResult::AGAIN;
|
return InputResult::AGAIN;
|
||||||
}
|
}
|
||||||
|
|
|
@ -66,6 +66,11 @@ class HttpdClient final : public BufferedSocket {
|
||||||
*/
|
*/
|
||||||
size_t current_position;
|
size_t current_position;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Is this a HEAD request?
|
||||||
|
*/
|
||||||
|
bool head_method;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* If DLNA streaming was an option.
|
* If DLNA streaming was an option.
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Reference in New Issue