+  HandyCache форум
|-+  Главная категория» English forum» Problem With BeforeAnswerBodySend Event
Имя пользователя:
Пароль:
Страниц: [1]   Вниз
  Отправить эту тему    Печать  
Автор Тема: Problem With BeforeAnswerBodySend Event  (Прочитано 3274 раз)
0 Пользователей и 1 Гость смотрят эту тему.
bdstd
Новичок
*

Репутация: +0/-0
Offline Offline

Сообщений: 14


« : 24 февраля 2017, 03:13:01 »

Hai mai62

I have made an extension, and seems to have worked

like this

Код:
--[[ <HCExtension>
@name Save 206 Partial (Resumable)
@author bdstd
@rule ^.*/mobileoc\.music\.tc\.qq\.com/(\w+\.\w+)\?.*
@event Timer1m/temp_cleaner
@event AnswerHeaderReceived/answer
</HCExtension> ]]
function temp_cleaner()
hc.delete_file(hc.cache_path..'206_Partial_Temp')
end
function answer()
if hc.action=='dont_update' or hc.action=='dont_update-' then return end
if hc.method~='GET' then return end
if not re.find(hc.answer_header, [[^HTTP/[\d\.]+\s206]]) then return end
if re.find(hc.request_header, [[^.*Range:\sbytes=(\d+)\-.*]]) then
request_byte = tonumber(re.substr(1))
fname = hc.get_cache_file_name(hc.url)
hc.action = 'dont_save'
hc.call_me_for('BeforeAnswerHeaderSend', 'partial_processing')
end
end
function partial_processing()
if re.find(hc.answer_header, [[^ETag:\s([^\r\n]+)\r\n]]) then
local val = hc.crc32(re.substr(1))
fname_temp = hc.cache_path..'206_Partial_Temp\\'..hc.crc32(fname)..val
elseif re.find(hc.answer_header, [[^Last\-Modified:\s([^\r\n]+)\r\n]]) then
local val = hc.crc32(re.substr(1))
fname_temp = hc.cache_path..'206_Partial_Temp\\'..hc.crc32(fname)..val
else
return
end
hc.prepare_path(fname)
hc.prepare_path(fname_temp)
if request_byte==0 then
hc.monitor_string = 'Save-206'
mark = io.open(fname_temp..'.buf', 'w')
write_data = io.open(fname_temp, 'w+b')
hc.call_me_for('BeforeAnswerBodySend', 'write_byte')
else
while hc.get_cache_file_size(fname_temp..'.buf')~=-1 do
hc.sleep(1000)
os.remove(fname_temp..'.buf')
if hc.client_connected==false then return end
end
if request_byte==hc.get_cache_file_size(fname_temp) then
hc.monitor_string = 'Save-206(Resuming)'
mark = io.open(fname_temp..'.buf', 'w')
write_data = io.open(fname_temp, 'a+b')
hc.call_me_for('BeforeAnswerBodySend', 'write_byte')
end
end
end
function write_byte()
if hc.last_part==true then
write_data:write(hc.answer_body)
write_data:close()
mark:close()
os.remove(fname_temp..'.buf')
if re.find(hc.answer_header, [[^Content\-Range:\sbytes\s\d+\-(\d+)/(\d+)\r\n]]) then
if hc.get_cache_file_size(fname_temp)==tonumber(re.substr(2)) then
if os.rename(fname_temp, fname)==true then
hc.monitor_string = 'Completed'
end
end
end
else
write_data:write(hc.answer_body)
end
end

problems arise, HandyCache replacing "Content-Length:" field with "Transfer-Encoding: chunked" automatically. this makes some web or game patcher having problems

How to prevent event BeforeAnswerBodySend do that?

Sorry for my bad english, i'm using google translate Улыбка
Сообщить модератору   Записан
KPu3uC B Poccuu
Пользователь
**

Репутация: +0/-1
Offline Offline

Сообщений: 68


WWW
« Ответ #1 : 09 февраля 2021, 13:31:22 »

It's a pity this topic has been ignored because I also suffer from this oddity. Why would HC out of the blue do this? It's clearly inferior behavior if the content length is known beforehand (and it's known when cache is used). And if my extension explicitly sets `Transfer-Encoding` HC has no business changing it IMHO.
Сообщить модератору   Записан
Страниц: [1]   Вверх
  Отправить эту тему    Печать  

 
Перейти в: