| 191 | } |
| 192 | |
| 193 | void HTTPSession::processOptions(Exception& ex,const HTTPPacket& request) { |
| 194 | |
| 195 | // Control methods quiested |
| 196 | if (request.accessControlRequestMethod&HTTP::COMMAND_DELETE) { |
| 197 | ex.set(Exception::PROTOCOL,"Delete not allowed"); |
| 198 | return; |
| 199 | } |
| 200 | |
| 201 | HTTP_BEGIN_HEADER(_writer.writeRaw("200 OK").packet) |
| 202 | HTTP_ADD_HEADER("Access-Control-Allow-Methods", EXPAND("GET, HEAD, PUT, PATH, POST, OPTIONS")) |
| 203 | if (request.accessControlRequestHeaders) |
| 204 | HTTP_ADD_HEADER("Access-Control-Allow-Headers", request.accessControlRequestHeaders) |
| 205 | HTTP_ADD_HEADER("Access-Control-Max-Age", EXPAND("86400")) // max age of 24 hours |
| 206 | HTTP_END_HEADER |
| 207 | } |
| 208 | |
| 209 | void HTTPSession::processGet(Exception& ex, HTTPPacket& request, QueryReader& parameters) { |
| 210 | // use index http option in the case of GET request on a directory |
| 211 | |
| 212 | File& file(request.file); |
| 213 | |
| 214 | if (!file.isFolder()) { |
| 215 | // FILE // |
| 216 | |
| 217 | // 1 - priority on client method |
| 218 | if (file.extension().empty() && peer.onMessage(ex, file.name(), parameters)) // can be method! |
| 219 | return; |
| 220 | |
| 221 | // 2 - try to get a file |
| 222 | shared_ptr<Parameters> pFileParams(new MapParameters()); |
| 223 | ParameterWriter parameterWriter(*pFileParams); |
| 224 | if (!peer.onRead(ex, parameters, file, parameterWriter)) { |
| 225 | if (!ex) |
| 226 | ex.set(Exception::PERMISSION, "No authorization to see the content of ", file.path()); |
| 227 | return; |
| 228 | } |
| 229 | // If onRead has been authorised, and that the file is a multimedia file, and it doesn't exists (no VOD, filePath.lastModified()==0 means "doesn't exists") |
| 230 | // Subscribe for a live stream with the basename file as stream name |
| 231 | if (!file.exists()) { |
| 232 | if (request.contentType == HTTP::CONTENT_ABSENT) |
| 233 | request.contentType = HTTP::ExtensionToMIMEType(file.extension(), request.contentSubType); |
| 234 | if (request.contentType == HTTP::CONTENT_VIDEO || request.contentType == HTTP::CONTENT_AUDIO) { |
| 235 | if (openSubscribtion(ex, file.baseName(), _writer)) |
| 236 | return; |
| 237 | } |
| 238 | } |
| 239 | if (!file.isFolder()) |
| 240 | return _writer.writeFile(file.path(), pFileParams); |
| 241 | } |
| 242 | |
| 243 | |
| 244 | // FOLDER // |
| 245 | if (_index.find_last_of('.') == string::npos && peer.onMessage(ex, _index, parameters)) // can be method! |
| 246 | return; |
| 247 | |
| 248 | // Redirect to the file (get name to prevent path insertion), if impossible (_index empty or invalid) list directory |
| 249 | if (!_index.empty()) |
| 250 | file.setPath(file.path(),_index); |