Commit 9ec7d39a authored by ROOL's avatar ROOL 🤖
Browse files

Finish implementation of head/body/both flags

Detail:
  Per Docs/SWIs the flags in R5 (or R2 b8-15) should allow a client to request only the head/body or both, but the implementation was incomplete in places.
  Where http_write_data_to_client() is called, check what the request was and filter appropriately.
Admin:
  Submission from Chris Mahoney.

Version 0.98. Tagged as 'HTTP-0_98'
parent 8e124197
/* (0.97) /* (0.98)
* *
* This file is automatically maintained by srccommit, do not edit manually. * This file is automatically maintained by srccommit, do not edit manually.
* Last processed by srccommit version: 1.1. * Last processed by srccommit version: 1.1.
* *
*/ */
#define Module_MajorVersion_CMHG 0.97 #define Module_MajorVersion_CMHG 0.98
#define Module_MinorVersion_CMHG #define Module_MinorVersion_CMHG
#define Module_Date_CMHG 17 May 2018 #define Module_Date_CMHG 19 May 2018
#define Module_MajorVersion "0.97" #define Module_MajorVersion "0.98"
#define Module_Version 97 #define Module_Version 98
#define Module_MinorVersion "" #define Module_MinorVersion ""
#define Module_Date "17 May 2018" #define Module_Date "19 May 2018"
#define Module_ApplicationDate "17-May-18" #define Module_ApplicationDate "19-May-18"
#define Module_ComponentName "HTTP" #define Module_ComponentName "HTTP"
#define Module_ComponentPath "castle/RiscOS/Sources/Networking/Fetchers/HTTP" #define Module_ComponentPath "castle/RiscOS/Sources/Networking/Fetchers/HTTP"
#define Module_FullVersion "0.97" #define Module_FullVersion "0.98"
#define Module_HelpVersion "0.97 (17 May 2018)" #define Module_HelpVersion "0.98 (19 May 2018)"
#define Module_LibraryVersionInfo "0:97" #define Module_LibraryVersionInfo "0:98"
...@@ -411,7 +411,14 @@ int parse_http_header(char *const buffer, int buflen, Session *ses, _kernel_swi_ ...@@ -411,7 +411,14 @@ int parse_http_header(char *const buffer, int buflen, Session *ses, _kernel_swi_
/* Are we pumping a header out to the client? */ /* Are we pumping a header out to the client? */
if (ses->current_header != NULL) { if (ses->current_header != NULL) {
char *databuffer = ses->current_header + ses->hdrptr; char *databuffer = ses->current_header + ses->hdrptr;
ses->hdrptr += http_write_data_to_client(r, databuffer, strlen(databuffer)); if (ses->data_wanted > 0) {
/* Head or both */
ses->hdrptr += http_write_data_to_client(r, databuffer, strlen(databuffer));
}
else {
/* Body only */
ses->hdrptr += strlen(databuffer);
}
if (ses->current_header[ses->hdrptr] == '\0') { if (ses->current_header[ses->hdrptr] == '\0') {
if (ses->final_pump) { if (ses->final_pump) {
ses->donehead = TRUE; ses->donehead = TRUE;
...@@ -715,7 +722,14 @@ int parse_http_header(char *const buffer, int buflen, Session *ses, _kernel_swi_ ...@@ -715,7 +722,14 @@ int parse_http_header(char *const buffer, int buflen, Session *ses, _kernel_swi_
if (ses->current_header != NULL) { if (ses->current_header != NULL) {
size_t length = strlen(ses->current_header); size_t length = strlen(ses->current_header);
wrote = http_write_data_to_client(r, ses->current_header, length); if (ses->data_wanted > 0) {
/* Head or both */
wrote = http_write_data_to_client(r, ses->current_header, length);
}
else {
/* Body only */
wrote = 0;
}
if (wrote == length) { if (wrote == length) {
if (ses->final_pump) { if (ses->final_pump) {
ses->donehead = TRUE; ses->donehead = TRUE;
......
...@@ -352,7 +352,10 @@ static void http_reading_response(_kernel_swi_regs *r, Session *ses) ...@@ -352,7 +352,10 @@ static void http_reading_response(_kernel_swi_regs *r, Session *ses)
if (dataread > 0) { if (dataread > 0) {
ses->sent += dataread; ses->sent += dataread;
http_write_data_to_client(r, buffer, dataread); if (ses->data_wanted != 1) {
/* Body wanted */
http_write_data_to_client(r, buffer, dataread);
}
if (ses->chunking) { if (ses->chunking) {
if (ses->chunk_bytes == 0 && r->r[3] > 0) { if (ses->chunk_bytes == 0 && r->r[3] > 0) {
/* See comment in block containing call to http_process_chunks about /* See comment in block containing call to http_process_chunks about
......
...@@ -117,7 +117,7 @@ static _kernel_oserror *http_start_main(_kernel_swi_regs *r) ...@@ -117,7 +117,7 @@ static _kernel_oserror *http_start_main(_kernel_swi_regs *r)
method = method & 0xFF; method = method & 0xFF;
} }
else { else {
ses->data_wanted = (r->r[5] > 0); ses->data_wanted = r->r[5] & 0xFF;
} }
if (http_method_text(method) == NULL) { if (http_method_text(method) == NULL) {
......
...@@ -85,7 +85,7 @@ typedef struct session { ...@@ -85,7 +85,7 @@ typedef struct session {
unsigned int sent; /* Amount of data sent to the client in total by this module */ unsigned int sent; /* Amount of data sent to the client in total by this module */
unsigned int to_send; /* Amount of data left to send to server */ unsigned int to_send; /* Amount of data left to send to server */
unsigned int total_send; /* Total size of data to send to server */ unsigned int total_send; /* Total size of data to send to server */
unsigned int data_wanted; /* No idea */ unsigned int data_wanted; /* Response parts wanted - 0 for body only, 1 for head only, 2 for both */
int method; /* HTTP method being used - no idea on representation */ int method; /* HTTP method being used - no idea on representation */
char *data; /* Client data to be sent to server?? (not sure) */ char *data; /* Client data to be sent to server?? (not sure) */
int data_len; /* Size of data pointed to by 'data'. strlen(data) if not known */ int data_len; /* Size of data pointed to by 'data'. strlen(data) if not known */
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment