Skip to content
Snippets Groups Projects
Commit 328ed84f authored by deuce's avatar deuce
Browse files

Implement OPTIONS request... I seriously doubt this will help anyone

with anything though, since there aren't any options implemented (and even
some required features are missing)

This will stop 501 errors on OPTIONS requests... but it shouldn't make the
slightest difference to anyone.
parent d49b1d7c
No related branches found
No related tags found
No related merge requests found
...@@ -223,12 +223,15 @@ static char* http_vers[] = { ...@@ -223,12 +223,15 @@ static char* http_vers[] = {
enum { enum {
HTTP_HEAD HTTP_HEAD
,HTTP_GET ,HTTP_GET
,HTTP_POST
,HTTP_OPTIONS
}; };
static char* methods[] = { static char* methods[] = {
"HEAD" "HEAD"
,"GET" ,"GET"
,"POST" ,"POST"
,"OPTIONS"
,NULL /* terminator */ ,NULL /* terminator */
}; };
...@@ -874,6 +877,8 @@ static BOOL send_headers(http_session_t *session, const char *status) ...@@ -874,6 +877,8 @@ static BOOL send_headers(http_session_t *session, const char *status)
status_line=status; status_line=status;
ret=stat(session->req.physical_path,&stats); ret=stat(session->req.physical_path,&stats);
if(session->req.method==HTTP_OPTIONS)
ret=-1;
if(!ret && session->req.if_modified_since && (stats.st_mtime <= session->req.if_modified_since) && !session->req.dynamic) { if(!ret && session->req.if_modified_since && (stats.st_mtime <= session->req.if_modified_since) && !session->req.dynamic) {
status_line="304 Not Modified"; status_line="304 Not Modified";
ret=-1; ret=-1;
...@@ -930,11 +935,11 @@ static BOOL send_headers(http_session_t *session, const char *status) ...@@ -930,11 +935,11 @@ static BOOL send_headers(http_session_t *session, const char *status)
/* Entity Headers */ /* Entity Headers */
if(session->req.dynamic) { if(session->req.dynamic) {
safe_snprintf(header,sizeof(header),"%s: %s",get_header(HEAD_ALLOW),"GET, HEAD, POST"); safe_snprintf(header,sizeof(header),"%s: %s",get_header(HEAD_ALLOW),"GET, HEAD, POST, OPTIONS");
safecat(headers,header,MAX_HEADERS_SIZE); safecat(headers,header,MAX_HEADERS_SIZE);
} }
else { else {
safe_snprintf(header,sizeof(header),"%s: %s",get_header(HEAD_ALLOW),"GET, HEAD"); safe_snprintf(header,sizeof(header),"%s: %s",get_header(HEAD_ALLOW),"GET, HEAD, OPTIONS");
safecat(headers,header,MAX_HEADERS_SIZE); safecat(headers,header,MAX_HEADERS_SIZE);
} }
...@@ -2060,11 +2065,14 @@ static BOOL check_request(http_session_t * session) ...@@ -2060,11 +2065,14 @@ static BOOL check_request(http_session_t * session)
} }
if(stat(path,&sb) || IS_PATH_DELIM(*(lastchar(path))) || send404) { if(stat(path,&sb) || IS_PATH_DELIM(*(lastchar(path))) || send404) {
/* OPTIONS requests never return 404 errors (ala Apache) */
if(session->req.method!=HTTP_OPTIONS) {
if(startup->options&WEB_OPT_DEBUG_TX) if(startup->options&WEB_OPT_DEBUG_TX)
lprintf(LOG_DEBUG,"%04d 404 - %s does not exist",session->socket,path); lprintf(LOG_DEBUG,"%04d 404 - %s does not exist",session->socket,path);
send_error(session,error_404); send_error(session,error_404);
return(FALSE); return(FALSE);
} }
}
SAFECOPY(session->req.physical_path,path); SAFECOPY(session->req.physical_path,path);
add_env(session,"SCRIPT_NAME",session->req.virtual_path); add_env(session,"SCRIPT_NAME",session->req.virtual_path);
add_env(session,"SCRIPT_FILENAME",session->req.physical_path); add_env(session,"SCRIPT_FILENAME",session->req.physical_path);
...@@ -2837,7 +2845,7 @@ js_write(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) ...@@ -2837,7 +2845,7 @@ js_write(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
if((str=JS_ValueToString(cx, argv[i]))==NULL) if((str=JS_ValueToString(cx, argv[i]))==NULL)
continue; continue;
if(session->req.sent_headers) { if(session->req.sent_headers) {
if(session->req.method!=HTTP_HEAD) if(session->req.method!=HTTP_HEAD && session->req.method!=HTTP_OPTIONS)
sendsocket(session->socket, JS_GetStringBytes(str), JS_GetStringLength(str)); sendsocket(session->socket, JS_GetStringBytes(str), JS_GetStringLength(str));
} }
else else
...@@ -2864,7 +2872,7 @@ js_writeln(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) ...@@ -2864,7 +2872,7 @@ js_writeln(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
/* Should this do the whole \r\n thing for Win32 *shudder* */ /* Should this do the whole \r\n thing for Win32 *shudder* */
if(session->req.sent_headers) { if(session->req.sent_headers) {
if(session->req.method!=HTTP_HEAD) if(session->req.method!=HTTP_HEAD && session->req.method!=HTTP_OPTIONS)
sendsocket(session->socket, "\n", 1); sendsocket(session->socket, "\n", 1);
} }
else else
...@@ -3197,6 +3205,10 @@ static void respond(http_session_t * session) ...@@ -3197,6 +3205,10 @@ static void respond(http_session_t * session)
{ {
BOOL send_file=TRUE; BOOL send_file=TRUE;
if(session->req.method==HTTP_OPTIONS) {
send_headers(session,session->req.status);
}
else {
if(session->req.dynamic==IS_CGI) { if(session->req.dynamic==IS_CGI) {
if(!exec_cgi(session)) { if(!exec_cgi(session)) {
send_error(session,error_500); send_error(session,error_500);
...@@ -3218,7 +3230,8 @@ static void respond(http_session_t * session) ...@@ -3218,7 +3230,8 @@ static void respond(http_session_t * session)
session->req.mime_type=get_mime_type(strrchr(session->req.physical_path,'.')); session->req.mime_type=get_mime_type(strrchr(session->req.physical_path,'.'));
send_file=send_headers(session,session->req.status); send_file=send_headers(session,session->req.status);
} }
if(session->req.method==HTTP_HEAD) }
if(session->req.method==HTTP_HEAD || session->req.method==HTTP_OPTIONS)
send_file=FALSE; send_file=FALSE;
if(send_file) { if(send_file) {
int snt=0; int snt=0;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment