mirror of
https://github.com/sheumann/NetDisk.git
synced 2025-01-02 17:30:38 +00:00
Small refactoring.
This commit is contained in:
parent
179c0afe56
commit
a485918d44
29
http.c
29
http.c
@ -33,6 +33,18 @@ enum ResponseHeader {
|
||||
LOCATION,
|
||||
};
|
||||
|
||||
static void
|
||||
UpdateRequestRange(Session *sess, unsigned long start, unsigned long end) {
|
||||
int count =
|
||||
snprintf(sess->httpRequestRange, 10+1+10+5, "%lu-%lu\r\n\r\n", start, end);
|
||||
|
||||
sess->desiredStart = start;
|
||||
sess->desiredEnd = end;
|
||||
|
||||
sess->httpRequestLen = sess->httpRequestRange - sess->httpRequest + count;
|
||||
}
|
||||
|
||||
|
||||
Boolean BuildHTTPRequest(Session *sess, char *resourceStr) {
|
||||
int sizeNeeded = 0;
|
||||
int rangeOffset;
|
||||
@ -77,25 +89,16 @@ Boolean BuildHTTPRequest(Session *sess, char *resourceStr) {
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
void UpdateRequestRange(Session *sess, unsigned long start, unsigned long end) {
|
||||
int count =
|
||||
snprintf(sess->httpRequestRange, 10+1+10+5, "%lu-%lu\r\n\r\n", start, end);
|
||||
|
||||
sess->desiredStart = start;
|
||||
sess->desiredEnd = end;
|
||||
|
||||
sess->httpRequestLen = sess->httpRequestRange - sess->httpRequest + count;
|
||||
}
|
||||
|
||||
|
||||
enum RequestResult DoHTTPRequest(Session *sess) {
|
||||
enum RequestResult
|
||||
DoHTTPRequest(Session *sess, unsigned long start, unsigned long end) {
|
||||
top:;
|
||||
rlrBuff rlrBuff = {0};
|
||||
Word tcpError;
|
||||
Boolean wantRedirect = FALSE, gotRedirect = FALSE;
|
||||
enum RequestResult result;
|
||||
|
||||
UpdateRequestRange(sess, start, end);
|
||||
|
||||
sess->responseCode = 0;
|
||||
|
||||
/* Send out request */
|
||||
|
3
http.h
3
http.h
@ -18,7 +18,6 @@ enum RequestResult {
|
||||
};
|
||||
|
||||
Boolean BuildHTTPRequest(Session *sess, char *resourceStr);
|
||||
void UpdateRequestRange(Session *sess, unsigned long start, unsigned long end);
|
||||
enum RequestResult DoHTTPRequest(Session *sess);
|
||||
enum RequestResult DoHTTPRequest(Session *sess, unsigned long start, unsigned long end);
|
||||
|
||||
#endif
|
4
main.c
4
main.c
@ -47,7 +47,6 @@ int main(int argc, char **argv) {
|
||||
if (argc > 2) {
|
||||
startByte = strtoul(argv[2], NULL, 0);
|
||||
}
|
||||
UpdateRequestRange(&sess, startByte, startByte + 511);
|
||||
|
||||
printf("Request:\n");
|
||||
printf("=========\n");
|
||||
@ -60,7 +59,8 @@ int main(int argc, char **argv) {
|
||||
printf("=========\n");
|
||||
printf("\n", i);
|
||||
|
||||
enum RequestResult requestResult = DoHTTPRequest(&sess);
|
||||
enum RequestResult requestResult;
|
||||
requestResult = DoHTTPRequest(&sess, startByte, startByte + 511);
|
||||
printf("RequestResult %i\n", requestResult);
|
||||
printf("Response code %lu\n", sess.responseCode);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user