j commited on
Commit
016952f
·
1 Parent(s): b83c86d

experimenting with regexes

Browse files
reascripts/ReaSpeech/source/ReaSpeechAPI.lua CHANGED
@@ -193,25 +193,20 @@ end
193
  function ReaSpeechAPI.http_status_and_body(response)
194
  local headers, content = ReaSpeechAPI._split_curl_response(response)
195
  local last_status_line = headers[#headers] and headers[#headers][1] or ''
196
-
197
- local status = last_status_line:match("^HTTP/(%d+%.?%d*)%s+(%d+)")
198
- if not status then
199
- status = last_status_line:match(":status:%s*(%d+)")
200
- end
201
-
202
  if not status then
203
  return -1, 'Status not found in headers'
204
  end
205
-
206
  local body = {}
207
  for _, chunk in pairs(content) do
208
  table.insert(body, table.concat(chunk, "\n"))
209
  end
210
-
211
  return tonumber(status), table.concat(body, "\n")
212
  end
213
 
214
-
215
  function ReaSpeechAPI._split_curl_response(input)
216
  local line_iterator = ReaSpeechAPI._line_iterator(input)
217
  local chunk_iterator = ReaSpeechAPI._chunk_iterator(line_iterator)
 
193
  function ReaSpeechAPI.http_status_and_body(response)
194
  local headers, content = ReaSpeechAPI._split_curl_response(response)
195
  local last_status_line = headers[#headers] and headers[#headers][1] or ''
196
+
197
+ local status = last_status_line:match("HTTP/([12]%.?%d?) (200)")
 
 
 
 
198
  if not status then
199
  return -1, 'Status not found in headers'
200
  end
201
+
202
  local body = {}
203
  for _, chunk in pairs(content) do
204
  table.insert(body, table.concat(chunk, "\n"))
205
  end
206
+
207
  return tonumber(status), table.concat(body, "\n")
208
  end
209
 
 
210
  function ReaSpeechAPI._split_curl_response(input)
211
  local line_iterator = ReaSpeechAPI._line_iterator(input)
212
  local chunk_iterator = ReaSpeechAPI._chunk_iterator(line_iterator)