mirror of
https://github.com/servalproject/serval-dna.git
synced 2025-01-18 02:39:44 +00:00
rhizome direct http transport sends request, and receives http
reply (including if error). Doesn't capture the reply body yet. #9
This commit is contained in:
parent
e4896cd028
commit
e8009ac94a
@ -512,6 +512,9 @@ void rhizome_direct_http_dispatch(rhizome_direct_sync_request *r)
|
||||
char boundary[1024];
|
||||
snprintf(boundary,1024,"----%08lx%08lx",random(),random());
|
||||
|
||||
/* TODO: Refactor this code so that it uses our asynchronous framework.
|
||||
*/
|
||||
|
||||
int content_length=
|
||||
strlen("--")+strlen(boundary)+strlen("\r\n")+
|
||||
strlen("Content-Disposition: form-data; name=\"IHAVEs\"; filename=\"IHAVEs\"\r\n"
|
||||
@ -539,6 +542,7 @@ void rhizome_direct_http_dispatch(rhizome_direct_sync_request *r)
|
||||
int count=write(sock,&buffer[sent],len-sent);
|
||||
if (count<1) {
|
||||
DEBUGF("errno=%d, count=%d",errno,count);
|
||||
if (errno==EPIPE) goto rx;
|
||||
close(sock);
|
||||
goto end;
|
||||
}
|
||||
@ -552,6 +556,7 @@ void rhizome_direct_http_dispatch(rhizome_direct_sync_request *r)
|
||||
int count=write(sock,&r->cursor->buffer[sent],len-sent);
|
||||
if (count<1) {
|
||||
DEBUGF("errno=%d, count=%d",errno,count);
|
||||
if (errno==EPIPE) goto rx;
|
||||
close(sock);
|
||||
goto end;
|
||||
}
|
||||
@ -566,12 +571,34 @@ void rhizome_direct_http_dispatch(rhizome_direct_sync_request *r)
|
||||
int count=write(sock,&buffer[sent],len-sent);
|
||||
if (count<1) {
|
||||
DEBUGF("errno=%d, count=%d",errno,count);
|
||||
if (errno==EPIPE) goto rx;
|
||||
close(sock);
|
||||
goto end;
|
||||
}
|
||||
sent+=count;
|
||||
}
|
||||
|
||||
rx:
|
||||
/* request sent, now get response back. */
|
||||
buffer[0]=0; len=0;
|
||||
while(!http_header_complete(buffer,len,len)&&(len<8192))
|
||||
{
|
||||
int count=read(sock,&buffer[len],8192-len);
|
||||
if (count<1) {
|
||||
DEBUGF("errno=%d, count=%d",errno,count);
|
||||
close(sock);
|
||||
goto end;
|
||||
}
|
||||
len+=count;
|
||||
if (len>=8000) {
|
||||
DEBUGF("reply header too long");
|
||||
close(sock);
|
||||
goto end;
|
||||
}
|
||||
}
|
||||
|
||||
DEBUGF("Got HTTP header");
|
||||
dump("reply",(unsigned char *)buffer,len);
|
||||
|
||||
end:
|
||||
/* Warning: tail recursion when done this way.
|
||||
|
Loading…
Reference in New Issue
Block a user