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

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

Сообщений: 12


« : 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 Улыбка
Сообщить модератору   Записан
Страниц: [1]   Вверх
  Отправить эту тему    Печать  

 
Перейти в: