컴퓨터이야기/APACHE

- API(1) request_rec structure

백구씨쥔장 2005. 2. 1. 09:10
request_rec 구조체는 아파치 API의 가중 핵심이다.
이 구조체는 request의 모든 정보를 담고 있다.

request_rec는 모듈들이 공통으로 사용하는 정보와 core sever만 사용하는 정보를 통합해서 갖구 있다.

struct request_rec {

ap_pool *pool;
/*
* request의 lifetime동안 유효한 resource pool.
* 각각의 handler는 이것을 통해 메모리를 할당해야한다.
*/


conn_rec *connection;
/*
* 현재 request의 connection record에 대한 pointer.
* 인증에 사용될 username으로
* local, remote host 주소 등을 알아낼 수 있다.
*/


server_rec *server;
/* 현재 서버에 대한 정보를 담고 있다. */

request_rec *next;
/* request 를 redirect 시켰을 경우, redirect되어, 새로 생성된 request 의 포인터 */


request_rec *prev;
/* request 를 redirect 시켰을 경우, redirect 를 보낸 이전 request의 포인터 */

request_rec *main;
/*
* 아파치가 request를 처리함에 있어 international redirect나 기타 방법을 통해
* subrequest가 여러개 생성될 수있다.
* 이런 subrequest들은 linked list로 관리된다.
* 위의 request_rec *prev, request_rec *next, request_rec *main이
* 이런 linked list정보를 갖고 있다.
* request_rec *main은 클라이언트의 request(요청)를 실제로 처리하는
* request를 가리키는 포인터이다.
*/


char *the_request;
/* request의 첫째 라인, 로그남기는 위한 정보 */

int assbackwards;
/* HTTP/0.9, "simple" request */

int proxyreq;
/* request가 proxy request이면 0이 아닌값이된다. */

int header_only;
/* header-only request일 경우, 0이 아닌 값이 된다. */

char *protocol;
/*
* 브라우져의 요청 프로토콜의 이름과 버젼정보가 들어간다.
* 예) HTTP/1.0
*/


int proto_num;
/* 프로토콜의 버젼, 1.1 = 1001 */

const char *hostname;
/*
* Host 헤더나 URI에 포함된 host의 이름.
* DNS alias에 따라 꼭 virtualhost나 URI에 포함된 host정보와 같지는않다.
* 이 값을 얻기위해 ap_get_server_name() 함수를 사용해라.
*/


time_t request_time;
/* request를 받은 시간 */

char *status_line;
/* 아파치가 브라우져에게 보낸 status line 예) 200 */

int status;
/* 트랜잭션 상태코드의 numeric value */

char *method;
/* GET, HEAD, POST, etc. */

int method_number;
/* M_GET, M_POST, etc. */

int allowed;
/* Allowed methods - for 405, OPTIONS, etc */
/*
핸들러는 자신이 처리하지 않을 method를 가진 request는 모두 DECLINE(거부)하고, 자신이 처리할 수 있는 method를 가진 request만 받아야(OK) 한다.
이처럼 핸들러들은 자신이 처리할 method list값을 우선 설정해놔야한다.
예) r->allowed = M_GET | M_HEAD;
allowed 값은 OPTION, METHOD_NOT_ALLOWED, NOT_IMPLEMENTED 상태값을 필요로 하는 헤더에 "Allow"라는 헤더값을 보내주기위해 사용된다.
*/


int sent_bodyct;
/* byte count in stream is for body */

long bytes_sent;
/* body byte count, for easy access */

time_t mtime;
/* Time the resource was last modified */

/*** HTTP/1.1 connection-level features ***/
int chunked; /* sending chunked transfer-coding */
int byterange; /* number of byte ranges */
char *boundary; /* multipart/byteranges boundary */
const char *range; /* The Range: header */
long clength; /* The "real" content length */
long remaining; /* bytes left to read */
long read_length; /* bytes that have been read */
int read_body; /* how the request body should be read */
int read_chunked; /* reading chunked transfer-coding */

table *headers_in;
table *headers_out;
table *err_headers_out;
table *subprocess_env;
table *notes;
/*
* request의 각각의 처리단계에서 필요한 정보를 유지하고있는
* 아파치 table(key/value로 저장되어지는 데이터구조) record 포인터.
* "Table API" 를 이용해 정보에 접근할 수 있다.
*
* headers_in - 입력되는 HTTP 헤더정보.
* headers_out - 출력되는 HTTP 헤더정보.
* err_header_out - 에러 또는 subrequest의 출력정보
* subprocess_env - subprocess를 호출하기전에 환경변수복사, 유지
* note - 모듈에서 모듈로 특정정보를 넘길때 사용.
*/


const char *content_type;
const char *content_encoding;
/*
* 출력될 문서의 MIME content type과 encoding 정보를 갖구있다.
* MIME checking 단계에서 문서타입을 알아내기위해 읽는다.
* 빈번히 사용되므로 strcpy()를 사용하면 곤란~
*/


const char *handler;
/* content handler의 이름 */

array_header *content_languages;
/*
* 문서와 관련된 언어리스트를 참조하는 포인터.
* "Apache array API"를 이용해서 정보를 읽고, 조작할 수 있다.
* 보통 MIME checking단계에서 값이 설정되나 content handler가
* 그 값들을 변경할 수 있다.
*/


int no_cache;
/*
* true 로 세팅되어있다면 출력헤더에 "Expires" 필드를 붙인다.
* 이때 날짜와 시간은 입력헤더의 날짜, 시간과 같다.
*/


int no_local_copy;

char *unparsed_uri;
/* 본래의 URI 값 */

char *uri;
/* URI중 path 부분의 값 */

char *filename;
char *path_info;

char *args;
/* QUERY_ARGS */

struct stat finfo;
/*
* 요청된 파일의 가장 최근 stat()정보를 갖구 있다.
* 이 필드의 값을 사용하여 stat()호출을 줄일 수 있다.
*
* 예) 파일의 변경시간을 출력하는 예
if(S_ISDIR(r->finfo.st_mode)) {
ap_rprintf(r, "%s is a directory\n", r->filename);
} else {
ap_rprintf(r, "Last Modified: %s\n"
ap_ht_time(r->pool, r->finfo.st_mtime, timefmt, 0));
}
* 파일이 없다면 ST_MODE 값은 0
*/


uri_components parsed_uri;
/*
* 요청한 URI를 쉽게 해석하기 위해 URI를 미리 파싱하여 정보를 분리하여
* 갖고 있는 구조체. 아직 테스트중이다.
*/


void *per_dir_config;
void *request_config;
/*
* 모듈의 환경설정 정보들로써 직접 수정하면 안된다.
* per_dir_config는 아주 빈번히 사용되는 환경설정정보
* request_config는 subrequest로 전달될 사용자설정정보
*/


const struct htaccess_result *htaccess;
/*
* a linked list of the configuration directives in the .htaccess files
* accessed by this request.
* N.B. always add to the head of the list, _never_ to the end.
* that way, a sub request's list can (temporarily) point to a parent's list
*
* Things placed at the end of the record to avoid breaking binary
* compatibility. It would be nice to remember to reorder the entire
* record to improve 64-bit alignment the next time we need to break
* binary compatibility for some other reason.
*/


unsigned expecting_100;
/* is client waiting for a 100 response? */

};