99 |
99 |
100 return fd; |
100 return fd; |
101 } |
101 } |
102 |
102 |
103 int send_file(pblock *pb, Session *sn, Request *rq) { |
103 int send_file(pblock *pb, Session *sn, Request *rq) { |
104 printf("test_service\n"); |
|
105 |
|
106 // request body test begin |
|
107 char *ctval = pblock_findkeyval(pb_key_content_length, rq->headers); |
|
108 if(ctval != NULL) { |
|
109 printf("read request body\n"); |
|
110 |
|
111 printf("netbuf{%d}\n", sn->inbuf); |
|
112 |
|
113 int c; |
|
114 while((c = netbuf_getc(sn->inbuf)) != IO_EOF) { |
|
115 putchar(c); |
|
116 } |
|
117 printf("\n"); |
|
118 } |
|
119 |
|
120 |
|
121 // end test |
|
122 |
|
123 int fd = prepare_service_file(sn, rq); |
104 int fd = prepare_service_file(sn, rq); |
124 if(fd < 0) { |
105 if(fd < 0) { |
125 /* TODO: service error */ |
106 /* TODO: service error */ |
126 http_start_response(sn, rq); |
107 http_start_response(sn, rq); |
127 return REQ_PROCEED; |
108 return REQ_PROCEED; |
130 /* send file*/ |
111 /* send file*/ |
131 SystemIOStream *io = (SystemIOStream*) sn->csd; |
112 SystemIOStream *io = (SystemIOStream*) sn->csd; |
132 |
113 |
133 off_t fileoffset = 0; |
114 off_t fileoffset = 0; |
134 int len = atoi(pblock_findkeyval(pb_key_content_length, rq->srvhdrs)); |
115 int len = atoi(pblock_findkeyval(pb_key_content_length, rq->srvhdrs)); |
135 printf("content-length: %d\n", len); |
|
136 sendfile(io->fd, fd, &fileoffset, len); |
116 sendfile(io->fd, fd, &fileoffset, len); |
137 |
117 |
138 close(fd); |
118 close(fd); |
139 |
119 |
140 return REQ_PROCEED; |
120 return REQ_PROCEED; |