free(headers);
headers = NULL;
}
+ unsigned long long conlen = 0;
while(true) {
int len = recv(sock, buf, BUFFER_SIZE, 0);
if(len <= 0) goto goquit;
int i;
for(i = 0; i < len; i++) {
cbuf[0] = buf[i];
+ if(conlen > 0){
+ conlen--;
+ printf("%c", cbuf[0]);
+ fflush(stdout);
+ continue;
+ }
if(state == 0) {
if(buf[i] == ' ') {
state = 1;
} else if(buf[i] == '\n') {
count++;
if(count == 2) {
- if(strcmp(method, "GET") == 0) {
+ if(strcmp(method, "POST") == 0) {
+ if(headers != NULL){
+ int j;
+ bool haslen = false;
+ for(j = 0; headers[j] != NULL; j += 2){
+ if(mandshurica_strcaseequ(headers[j], "Content-Length")){
+ haslen = true;
+ conlen = atoll(headers[j + 1]);
+ break;
+ }
+ }
+ if(!haslen){
+ send(sock, "HTTP/1.1 400 Bad Request\r\n", 17 + 9, 0);
+ send(sock, "Connection: keep-alive\r\n", 24, 0);
+ send(sock, "Content-Length: 0\r\n", 19, 0);
+ send(sock, "\r\n", 2, 0);
+ }
+ }else{
+ send(sock, "HTTP/1.1 400 Bad Request\r\n", 17 + 9, 0);
+ send(sock, "Connection: keep-alive\r\n", 24, 0);
+ send(sock, "Content-Length: 0\r\n", 19, 0);
+ send(sock, "\r\n", 2, 0);
+ }
+ }else if(strcmp(method, "GET") == 0) {
char* chpath = mandshurica_strcat(webroot, path);
struct stat st2;
if(stat(chpath, &st2) != 0) {