|
|
| version 1.87, 2020/10/12 14:28:53 | version 1.88, 2020/10/12 16:58:55 |
|---|---|
| Line 189 public: | Line 189 public: |
| } | } |
| } | } |
| int read_response(int sock, bool fail_on_status_ne_200); | |
| }; | }; |
| enum HTTP_response_state { | enum HTTP_response_state { |
| Line 197 enum HTTP_response_state { | Line 198 enum HTTP_response_state { |
| HTTP_BODY | HTTP_BODY |
| }; | }; |
| static int http_read_response(HTTP_response& response, int sock, bool fail_on_status_ne_200) { | int HTTP_response::read_response(int sock, bool fail_on_status_ne_200) { |
| HTTP_response_state state=HTTP_STATUS_CODE; | HTTP_response_state state=HTTP_STATUS_CODE; |
| int result=0; | int result=0; |
| size_t chunk_size=0x400*16; | size_t chunk_size=0x400*16; |
| response.resize(2*chunk_size); | resize(2*chunk_size); |
| while(response.read(sock, chunk_size)){ | while(read(sock, chunk_size)){ |
| switch(state){ | switch(state){ |
| case HTTP_STATUS_CODE: { | case HTTP_STATUS_CODE: { |
| size_t status_size=response.first_line(); | size_t status_size=first_line(); |
| if(!status_size) | if(!status_size) |
| break; | break; |
| const char *status=response.status_code(pa_strdup(response.buf, status_size), result); | const char *status=status_code(pa_strdup(buf, status_size), result); |
| if(!result || fail_on_status_ne_200 && result!=200) | if(!result || fail_on_status_ne_200 && result!=200) |
| throw Exception("http.status", status ? new String(status) : &String::Empty, "invalid HTTP response status"); | throw Exception("http.status", status ? new String(status) : &String::Empty, "invalid HTTP response status"); |
| Line 220 static int http_read_response(HTTP_respo | Line 221 static int http_read_response(HTTP_respo |
| } | } |
| case HTTP_HEADERS: { | case HTTP_HEADERS: { |
| if(!response.body_start()) | if(!body_start()) |
| break; | break; |
| response.parse_headers(); | parse_headers(); |
| size_t content_length=check_file_size(response.headers.content_length, response.url); | size_t content_length=check_file_size(headers.content_length, url); |
| if(content_length>0 && (content_length + response.body_offset) > response.length){ | if(content_length>0 && (content_length + body_offset) > length){ |
| response.resize(content_length + response.body_offset + 0x400*64); | resize(content_length + body_offset + 0x400*64); |
| } | } |
| state=HTTP_BODY; | state=HTTP_BODY; |
| Line 242 static int http_read_response(HTTP_respo | Line 243 static int http_read_response(HTTP_respo |
| } | } |
| if(state==HTTP_STATUS_CODE) | if(state==HTTP_STATUS_CODE) |
| throw Exception("http.response", &response.url, "bad response from host - no status found (size=%u)", response.length); | throw Exception("http.response", &url, "bad response from host - no status found (size=%u)", length); |
| if(state==HTTP_HEADERS){ | if(state==HTTP_HEADERS){ |
| response.parse_headers(); | parse_headers(); |
| response.body_offset=response.length; | body_offset=length; |
| } | } |
| return result; | return result; |
| Line 322 static int http_request(HTTP_response& r | Line 323 static int http_request(HTTP_response& r |
| throw Exception("http.timeout", 0, "error sending request: %s (%d)", pa_socks_strerr(no), no); | throw Exception("http.timeout", 0, "error sending request: %s (%d)", pa_socks_strerr(no), no); |
| } | } |
| result=http_read_response(response, sock, fail_on_status_ne_200); | result=response.read_response(sock, fail_on_status_ne_200); |
| closesocket(sock); | closesocket(sock); |
| #ifdef PA_USE_ALARM | #ifdef PA_USE_ALARM |
| alarm(0); | alarm(0); |
| Line 1077 int HTTPD_Server::bind(const char *host_ | Line 1078 int HTTPD_Server::bind(const char *host_ |
| return sock; | return sock; |
| } | } |
| int ready(int fd,int operation,int timeout_value){ | static int ready(int fd,int operation,int timeout_value){ |
| struct timeval timeout = {0, timeout_value * 1000}; | struct timeval timeout = {0, timeout_value * 1000}; |
| fd_set fds; | fd_set fds; |
| FD_ZERO(&fds); | FD_ZERO(&fds); |