@@ -586,6 +586,11 @@ int HttpHandler::defaultStaticHandler() {
586586 }
587587 long total = file->size ();
588588 if (to == 0 || to >= total) to = total - 1 ;
589+ if (from < 0 || from >= total || to < from) {
590+ closeFile ();
591+ resp->SetHeader (" Content-Range" , hv::asprintf (" bytes */%ld" , total));
592+ return HTTP_STATUS_RANGE_NOT_SATISFIABLE ;
593+ }
589594 file->seek (from);
590595 status_code = HTTP_STATUS_PARTIAL_CONTENT ;
591596 resp->status_code = HTTP_STATUS_PARTIAL_CONTENT ;
@@ -1046,9 +1051,8 @@ int HttpHandler::handleForwardProxy() {
10461051 return connectProxy (req->url );
10471052 } else {
10481053 hlogw (" [%s:%d] Forbidden to forward proxy %s" , ip, port, req->url .c_str ());
1049- SetError ( HTTP_STATUS_FORBIDDEN , HTTP_STATUS_FORBIDDEN );
1054+ return SendHttpStatusResponse ( HTTP_STATUS_FORBIDDEN );
10501055 }
1051- return 0 ;
10521056}
10531057
10541058int HttpHandler::handleReverseProxy () {
@@ -1079,8 +1083,7 @@ int HttpHandler::connectProxy(const std::string& strUrl) {
10791083
10801084 if (forward_proxy && !service->IsTrustProxy (url.host .c_str ())) {
10811085 hlogw (" [%s:%d] Forbidden to proxy %s" , ip, port, url.host .c_str ());
1082- SetError (HTTP_STATUS_FORBIDDEN , HTTP_STATUS_FORBIDDEN );
1083- return 0 ;
1086+ return SendHttpStatusResponse (HTTP_STATUS_FORBIDDEN );
10841087 }
10851088
10861089 hloop_t * loop = hevent_loop (io);
@@ -1102,10 +1105,10 @@ int HttpHandler::connectProxy(const std::string& strUrl) {
11021105 hio_set_connect_timeout (upstream_io, service->proxy_connect_timeout );
11031106 }
11041107 if (service->proxy_read_timeout > 0 ) {
1105- hio_set_read_timeout (io , service->proxy_read_timeout );
1108+ hio_set_read_timeout (upstream_io , service->proxy_read_timeout );
11061109 }
11071110 if (service->proxy_write_timeout > 0 ) {
1108- hio_set_write_timeout (io , service->proxy_write_timeout );
1111+ hio_set_write_timeout (upstream_io , service->proxy_write_timeout );
11091112 }
11101113 hio_connect (upstream_io);
11111114 // NOTE: wait upstream_io connected then start read
0 commit comments