⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 request.h

📁 基于linux的http服务器.代码比较简单
💻 H
字号:
/*  Monkey HTTP Daemon v0.1.1 by EdsipeR (edsiper@linux-chile.org) *  -------------------------------------------------------------- *  This program is free software; you can redistribute it and/or modify *  it under the terms of the GNU General Public License as published by *  the Free Software Foundation; either version 2 of the License, or *  (at your option) any later version. * *  This program is distributed in the hope that it will be useful, *  but WITHOUT ANY WARRANTY; without even the implied warranty of *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the *  GNU Library General Public License for more details. * *  You should have received a copy of the GNU General Public License *  along with this program; if not, write to the Free Software *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */#include <unistd.h>#include "method.h"#include "mimetype.h"int request(int remote_fd) {		int  num_bytes,i=0;	char remote_request[1024];	char *aux_request, *method=0;	FILE *file_request;		/* Reciviendo Peticion */	if((num_bytes=recv(remote_fd,remote_request,1024,0))==-1) {		perror("recv");		return;	}		for(i=0; i<255 && remote_request[i]!='\0'; i++)	  if(remote_request[i] == '\n' || remote_request[i] == '\r')	 	   remote_request[i]='\0';	method      = strtok(remote_request, "\"\t ");	aux_request = strtok(NULL, "\"\t ");	strtok(aux_request,"?");	puts(method);	/* Verificacion de Method */	if(strcmp(method,"GET")!=0) {		requesterror(remote_fd,file_request,405);	}	else {		get_method(remote_fd,aux_request,num_bytes,file_request);	}		close(remote_fd);	return;}/* Manejo de errores en peticiones */int requesterror(int remote_fd, FILE *file_request, int num_error) {	int num_bytes;	char buffer[255];		switch(num_error) {	    	  case 404:      			  		send(remote_fd, "HTTP/1.1 404 Not Found\n\n", 24, 0);	  	   			 if( (file_request=fopen(FILE404,"r"))!=NULL){	     	 	  			 while(!feof(file_request)) {	     	 	  			 num_bytes = fread(buffer, 1, 255, file_request);				   	  		send(remote_fd,buffer,num_bytes,0);  				  		 }	   	               }			 	 	  						puts("Error 404 : Archivo no encontrado\n\n");     	     			break;    		  case 405:       		  			send(remote_fd, "HTTP/1.1 405 Method Not Allowed\n\n", 33, 0);      	   			 if( (file_request=fopen(FILE405,"r"))!=NULL){	     	 	  			 while(!feof(file_request)) {	     	 	  			 num_bytes = fread(buffer, 1, 255, file_request);				   	  		send(remote_fd,buffer,num_bytes,0);  				  		 }	   	               }			 	 								  puts("Error 405 : Metodo no implementado\n\n");						  break;	    		      }	return;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -