]> git.ipfire.org Git - thirdparty/tvheadend.git/commitdiff
Add support for HTTP HEAD command
authorAndreas Öman <andreas@lonelycoder.com>
Wed, 30 Jun 2010 18:06:33 +0000 (18:06 +0000)
committerAndreas Öman <andreas@lonelycoder.com>
Wed, 30 Jun 2010 18:06:33 +0000 (18:06 +0000)
src/http.c
src/http.h

index e0287d274c32ab3d6fc434a85455b910e73b4e93..580446c12f56be222fcf2bd49c4060f35e9619bd 100644 (file)
@@ -41,6 +41,7 @@ static LIST_HEAD(, http_path) http_paths;
 
 static struct strtab HTTP_cmdtab[] = {
   { "GET",        HTTP_CMD_GET },
+  { "HEAD",       HTTP_CMD_HEAD },
   { "POST",       HTTP_CMD_POST },
   { "DESCRIBE",   RTSP_CMD_DESCRIBE },
   { "OPTIONS",    RTSP_CMD_OPTIONS },
@@ -146,8 +147,6 @@ static const char *cachemonths[12] = {
 
 /**
  * Transmit a HTTP reply
- *
- * Return non-zero if we should disconnect (no more keep-alive)
  */
 void
 http_send_header(http_connection_t *hc, int rc, const char *content, 
@@ -217,8 +216,6 @@ http_send_header(http_connection_t *hc, int rc, const char *content,
 
 /**
  * Transmit a HTTP reply
- *
- * Return non-zero if we should disconnect (no more keep-alive)
  */
 static void
 http_send_reply(http_connection_t *hc, int rc, const char *content, 
@@ -227,6 +224,9 @@ http_send_reply(http_connection_t *hc, int rc, const char *content,
   http_send_header(hc, rc, content, hc->hc_reply.hq_size,
                   encoding, location, maxage);
   
+  if(hc->hc_no_output)
+    return;
+
   tcp_write_queue(hc->hc_fd, &hc->hc_reply);
 }
 
@@ -428,7 +428,10 @@ http_process_request(http_connection_t *hc, htsbuf_queue_t *spill)
     http_error(hc, HTTP_STATUS_BAD_REQUEST);
     return 0;
   case HTTP_CMD_GET:
-    return http_cmd_get(hc); 
+    return http_cmd_get(hc);
+  case HTTP_CMD_HEAD:
+    hc->hc_no_output = 1;
+    return http_cmd_get(hc);
   case HTTP_CMD_POST:
     return http_cmd_post(hc, spill);
   }
@@ -687,10 +690,12 @@ http_serve_requests(http_connection_t *hc, htsbuf_queue_t *spill)
   char hdrline[1024];
   char *argv[3], *c;
   int n;
-  
+
   htsbuf_queue_init(&hc->hc_reply, 0);
 
   do {
+    hc->hc_no_output  = 0;
+
     if(tcp_read_line(hc->hc_fd, cmdline, sizeof(cmdline), spill) < 0)
       return;
 
@@ -707,6 +712,7 @@ http_serve_requests(http_connection_t *hc, htsbuf_queue_t *spill)
     while(1) {
       if(tcp_read_line(hc->hc_fd, hdrline, sizeof(hdrline), spill) < 0)
        return;
+
       if(hdrline[0] == 0)
        break; /* header complete */
 
index d91be394f4e7b47355b961ad14edb24c23ae290c..9bf8b0630e9838a5e71eb4fc6975af5032ed4853 100644 (file)
@@ -61,6 +61,7 @@ typedef struct http_connection {
 
   enum {
     HTTP_CMD_GET,
+    HTTP_CMD_HEAD,
     HTTP_CMD_POST,
     RTSP_CMD_DESCRIBE,
     RTSP_CMD_OPTIONS,
@@ -86,6 +87,8 @@ typedef struct http_connection {
 
   struct config_head *hc_user_config;
 
+  int hc_no_output;
+
   /* Support for HTTP POST */
   
   char *hc_post_data;