loudapet / 42webserv

This project is about writing one's own HTTP server
2 stars 0 forks source link

Mime parser #73

Closed andreaulicna closed 1 month ago

andreaulicna commented 1 month ago

If we ever need this, as @loudapet said

// validate extension in targetResource
        if (!S_ISREG(statBuff.st_mode)) // if directory: no check
            return ;
        lastDotPos = this->targetResource.rfind('.');
        lastSlashPos = this->targetResource.rfind('/');
        // check if the last dot exists and comes after the last slash (if any)
        if (lastDotPos != std::string::npos && (lastSlashPos == std::string::npos || lastDotPos > lastSlashPos))
            extension = this->targetResource.substr(lastDotPos + 1);
        // check if extension in the set for the given content-type key
        it = mimeTypesDict.find(contentTypeValue);
        if (!extension.empty())
        { // if file: check extension against map
            if (it->second.find(extension) != it->second.end()) // if in map, return to continue
                return ;

        } // if file with no extension: no check - hence no code for else
    }
    if (!extension.empty()) // if no content and extension: 422
        this->response.updateStatus(422, "Unprocessable Content");