Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Filter by http status code #61

Merged
merged 1 commit into from
Feb 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/record.cc
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,11 @@ namespace warc2text {
// parse HTTP header
pos = content.find("HTTP/1.", last_pos);
if (pos == last_pos) { // found HTTP header
// parse HTTP status code
std::size_t space = content.find(" ", last_pos);
pos = content.find("\r\n", last_pos);
HTTPheader["status"] = content.substr(space + 1, (pos - space) - 1);

payload_start = read_header(content, pos + 2, HTTPheader);
if (payload_start == std::string::npos) {
// BOOST_LOG_TRIVIAL(warning) << "Response record without HTTP header";
Expand Down
8 changes: 7 additions & 1 deletion src/warcpreprocessor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,9 @@ namespace warc2text {
totalBytes(0),
textBytes(0),
langBytes(0),
tagFilters() {
tagFilters(),
statusFilter("^20[036] ?.*$")
{
if (!options.tag_filters_filename.empty())
util::readTagFiltersRegex(options.tag_filters_filename, tagFilters);

Expand Down Expand Up @@ -138,6 +140,10 @@ namespace warc2text {
if (record.getRecordType() != "response" && record.getRecordType() != "resource")
continue;

if (record.HTTPheaderExists("status") && !boost::regex_match(record.getHTTPheaderProperty("status"), statusFilter)) {
continue;
}

if (record.getWARCcontentType().find("application/http") == std::string::npos)
continue;

Expand Down
3 changes: 2 additions & 1 deletion src/warcpreprocessor.hh
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ namespace warc2text {
unsigned int langBytes;
util::umap_tag_filters_regex tagFilters;
boost::regex urlFilter;

const boost::regex statusFilter;

static const std::unordered_set<std::string> removeExtensions;
bool URLfilter(const std::string& url) const;

Expand Down