Ticket #781: http-head.patch

File http-head.patch, 2.8 kB (added by matthijs, 2 years ago)

Patch against 0.9.21

  • src/pulsecore/protocol-http.c

    old new  
    8080    STATE_DATA 
    8181}; 
    8282 
     83enum method { 
     84    METHOD_GET, 
     85    METHOD_HEAD 
     86}; 
     87 
    8388struct connection { 
    8489    pa_http_protocol *protocol; 
    8590    pa_iochannel *io; 
     
    8994    pa_client *client; 
    9095    enum state state; 
    9196    char *url; 
     97    enum method method; 
    9298    pa_module *module; 
    9399}; 
    94100 
     
    327333 
    328334    http_response(c, code, msg, MIME_HTML); 
    329335 
     336    if (c->method == METHOD_HEAD) { 
     337        pa_ioline_defer_close(c->line); 
     338        return; 
     339    } 
     340 
    330341    if (!text) 
    331342        text = msg; 
    332343 
     
    363374 
    364375    http_response(c, 200, "OK", MIME_HTML); 
    365376 
     377    if (c->method == METHOD_HEAD) { 
     378        pa_ioline_defer_close(c->line); 
     379        return; 
     380    } 
     381 
    366382    pa_ioline_puts(c->line, 
    367383                   HTML_HEADER(PACKAGE_NAME" "PACKAGE_VERSION) 
    368384                   "<h1>"PACKAGE_NAME" "PACKAGE_VERSION"</h1>\n" 
     
    402418 
    403419    http_response(c, 200, "OK", MIME_CSS); 
    404420 
     421    if (c->method == METHOD_HEAD) { 
     422        pa_ioline_defer_close(c->line); 
     423        return; 
     424    } 
     425 
    405426    pa_ioline_puts(c->line, 
    406427                   "body { color: black; background-color: white; }\n" 
    407428                   "a:link, a:visited { color: #900000; }\n" 
     
    420441    pa_assert(c); 
    421442 
    422443    http_response(c, 200, "OK", MIME_TEXT); 
     444 
     445    if (c->method == METHOD_HEAD) { 
     446        pa_ioline_defer_close(c->line); 
     447        return; 
     448    } 
     449 
    423450    r = pa_full_status_string(c->protocol->core); 
    424451    pa_ioline_puts(c->line, r); 
    425452    pa_xfree(r); 
     
    439466                   "<h2>Sinks</h2>\n" 
    440467                   "<p>\n"); 
    441468 
     469    if (c->method == METHOD_HEAD) { 
     470        pa_ioline_defer_close(c->line); 
     471        return; 
     472    } 
     473 
    442474    PA_IDXSET_FOREACH(sink, c->protocol->core->sinks, idx) { 
    443475        char *t, *m; 
    444476 
     
    566598    http_response(c, 200, "OK", t); 
    567599    pa_xfree(t); 
    568600 
     601    if(c->method == METHOD_HEAD) { 
     602        connection_unlink(c); 
     603        return; 
     604    } 
    569605    pa_ioline_set_callback(c->line, NULL, NULL); 
    570606 
    571607    if (pa_ioline_is_drained(c->line)) 
     
    606642 
    607643    switch (c->state) { 
    608644        case STATE_REQUEST_LINE: { 
    609             if (!pa_startswith(s, "GET ")) 
     645            if (pa_startswith(s, "GET ")) { 
     646                c->method = METHOD_GET; 
     647                s +=4; 
     648            } else if (pa_startswith(s, "HEAD ")) { 
     649                c->method = METHOD_HEAD; 
     650                s +=5; 
     651            } else { 
    610652                goto fail; 
    611  
    612             s +=4; 
     653            } 
    613654 
    614655            c->url = pa_xstrndup(s, strcspn(s, " \r\n\t?")); 
    615656            c->state = STATE_MIME_HEADER;