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
......@@ -223,12 +223,15 @@ static char* http_vers[] = {
enum {
HTTP_HEAD
,HTTP_GET
,HTTP_POST
,HTTP_OPTIONS
};
static char* methods[] = {
"HEAD"
,"GET"
,"POST"
,"OPTIONS"
,NULL /* terminator */
};
......@@ -874,6 +877,8 @@ static BOOL send_headers(http_session_t *session, const char *status)
status_line=status;
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) {
status_line="304 Not Modified";
ret=-1;
......@@ -930,11 +935,11 @@ static BOOL send_headers(http_session_t *session, const char *status)
/* Entity Headers */
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);
}
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);
}
......@@ -2060,10 +2065,13 @@ static BOOL check_request(http_session_t * session)
}
if(stat(path,&sb) || IS_PATH_DELIM(*(lastchar(path))) || send404) {
if(startup->options&WEB_OPT_DEBUG_TX)
lprintf(LOG_DEBUG,"%04d 404 - %s does not exist",session->socket,path);
send_error(session,error_404);
return(FALSE);
/* OPTIONS requests never return 404 errors (ala Apache) */
if(session->req.method!=HTTP_OPTIONS) {
if(startup->options&WEB_OPT_DEBUG_TX)
lprintf(LOG_DEBUG,"%04d 404 - %s does not exist",session->socket,path);
send_error(session,error_404);
return(FALSE);
}
}
SAFECOPY(session->req.physical_path,path);
add_env(session,"SCRIPT_NAME",session->req.virtual_path);
......@@ -2837,7 +2845,7 @@ js_write(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
if((str=JS_ValueToString(cx, argv[i]))==NULL)
continue;
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));
}
else
......@@ -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* */
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);
}
else
......@@ -3197,28 +3205,33 @@ static void respond(http_session_t * session)
{
BOOL send_file=TRUE;
if(session->req.dynamic==IS_CGI) {
if(!exec_cgi(session)) {
send_error(session,error_500);
if(session->req.method==HTTP_OPTIONS) {
send_headers(session,session->req.status);
}
else {
if(session->req.dynamic==IS_CGI) {
if(!exec_cgi(session)) {
send_error(session,error_500);
return;
}
session->req.finished=TRUE;
return;
}
session->req.finished=TRUE;
return;
}
if(session->req.dynamic==IS_SSJS) { /* Server-Side JavaScript */
if(!exec_ssjs(session,session->req.physical_path)) {
send_error(session,error_500);
return;
if(session->req.dynamic==IS_SSJS) { /* Server-Side JavaScript */
if(!exec_ssjs(session,session->req.physical_path)) {
send_error(session,error_500);
return;
}
sprintf(session->req.physical_path
,"%sSBBS_SSJS.%u.%u.html",temp_dir,getpid(),session->socket);
}
else {
session->req.mime_type=get_mime_type(strrchr(session->req.physical_path,'.'));
send_file=send_headers(session,session->req.status);
}
sprintf(session->req.physical_path
,"%sSBBS_SSJS.%u.%u.html",temp_dir,getpid(),session->socket);
}
else {
session->req.mime_type=get_mime_type(strrchr(session->req.physical_path,'.'));
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;
if(send_file) {
int snt=0;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment