Browse Source

Added OPTIONS support

git-svn-id: svn://svn.lighttpd.net/lighttpd/branches/lighttpd-1.3.x@467 152afb58-edef-0310-8abb-c4023f1b3aa9
svn/heads/lighttpd-1.3.x
Jan Kneschke 17 years ago
parent
commit
ffcc939e1b
  1. 1
      src/keyvalue.c
  2. 2
      src/keyvalue.h
  3. 14
      src/response.c
  4. 8
      tests/core.t

1
src/keyvalue.c

@ -15,6 +15,7 @@ static keyvalue http_methods[] = {
{ HTTP_METHOD_GET, "GET" },
{ HTTP_METHOD_POST, "POST" },
{ HTTP_METHOD_HEAD, "HEAD" },
{ HTTP_METHOD_OPTIONS, "OPTIONS" },
{ HTTP_METHOD_UNSET, NULL }
};

2
src/keyvalue.h

@ -7,7 +7,7 @@
# include <pcre.h>
#endif
typedef enum { HTTP_METHOD_UNSET = -1, HTTP_METHOD_GET, HTTP_METHOD_POST, HTTP_METHOD_HEAD } http_method_t;
typedef enum { HTTP_METHOD_UNSET = -1, HTTP_METHOD_GET, HTTP_METHOD_POST, HTTP_METHOD_HEAD, HTTP_METHOD_OPTIONS } http_method_t;
typedef enum { HTTP_VERSION_UNSET = -1, HTTP_VERSION_1_0, HTTP_VERSION_1_1 } http_version_t;
typedef struct {

14
src/response.c

@ -92,7 +92,12 @@ int http_response_write_basic_header(server *srv, connection *con) {
ds = (data_string *)con->response.headers->data[i];
if (ds->value->used && ds->key->used &&
0 != strncmp(ds->key->ptr, "X-LIGHTTPD-", sizeof("X-LIGHTTPD-") - 1)) {
0 != strncmp(ds->key->ptr, "X-LIGHTTPD-", sizeof("X-LIGHTTPD-") - 1) &&
/* headers we send */
!buffer_is_equal_string(ds->key, CONST_STR_LEN("Server")) &&
!buffer_is_equal_string(ds->key, CONST_STR_LEN("Date")) &&
!buffer_is_equal_string(ds->key, CONST_STR_LEN("Transfer-Encoding")) &&
!buffer_is_equal_string(ds->key, CONST_STR_LEN("Connection"))) {
BUFFER_APPEND_STRING_CONST(b, "\r\n");
buffer_append_string_buffer(b, ds->key);
BUFFER_APPEND_STRING_CONST(b, ": ");
@ -860,6 +865,13 @@ handler_t http_response_prepare(server *srv, connection *con) {
return HANDLER_FINISHED;
}
if (con->request.http_method == HTTP_METHOD_OPTIONS) {
con->file_finished = 1;
con->file_started = 1;
return HANDLER_FINISHED;
}
/* no decision yet, build conf->filename */
if (con->mode == DIRECT && con->physical.path->used == 0) {

8
tests/core.t

@ -9,7 +9,7 @@ BEGIN {
use strict;
use IO::Socket;
use Test::More tests => 15;
use Test::More tests => 16;
use LightyTest;
my $tf = LightyTest->new();
@ -115,6 +115,12 @@ EOF
$t->{RESPONSE} = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 404 } );
ok($tf->handle_http($t) == 0, 'URL-encoding, %00');
$t->{REQUEST} = ( <<EOF
OPTIONS * HTTP/1.0
EOF
);
$t->{RESPONSE} = ( { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } );
ok($tf->handle_http($t) == 0, 'OPTIONS');
ok($tf->stop_proc == 0, "Stopping lighttpd");

Loading…
Cancel
Save