Skip to content

Adds support for serving statichit content out of a directory#9107

Merged
zwoop merged 4 commits intoapache:masterfrom
zwoop:StaticHitDirs
Nov 17, 2022
Merged

Adds support for serving statichit content out of a directory#9107
zwoop merged 4 commits intoapache:masterfrom
zwoop:StaticHitDirs

Conversation

@zwoop
Copy link
Contributor

@zwoop zwoop commented Sep 26, 2022

This does some fairly expensive computations when producing the directory paths. This is intentional,
to make sure requests aren't escaping the specified directory and out elsewhere. This cleans out abusive
requests such as get /../../etc/hosts etc.

The idea is that rather than having to specify every individual file that the server should service, you can specify a
directory and every file (and subdirectory thereunder) can now be served.

@zwoop zwoop added this to the 10.0.0 milestone Sep 26, 2022
@zwoop zwoop self-assigned this Sep 26, 2022
@zwoop zwoop force-pushed the StaticHitDirs branch 2 times, most recently from da247f4 to 4bc29f7 Compare September 26, 2022 20:03
@bryancall
Copy link
Contributor

@zwoop You should really add labels to the PRs.

@zwoop
Copy link
Contributor Author

zwoop commented Sep 27, 2022

As a side note for the curious reader, if this is acceptable by the community, I'd like to add support for the HTTPD mime.types file, allowing the mime type to be defined by the suffix of the filename.

}
}
} else {
ret = {filePath};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess clang doesn't like the braces cause you're using a conversion operator not a constructor: https://en.cppreference.com/w/cpp/string/basic_string/operator_basic_string_view

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gah, thanks. I don't think it's a "clang" issue per se, it obviously worked with some clang compilers. Will look again when I get back.

@zwoop
Copy link
Contributor Author

zwoop commented Nov 9, 2022

[approve ci ubuntu]

TSHandleMLocRelease(reqp, hdr_loc, url_loc);
TSHandleMLocRelease(reqp, TS_NULL_MLOC, hdr_loc);

if (std::equal(dirPath.begin(), dirPath.end(), requested_file_path.begin()) &&
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need a case insensitive comparison for OSX?

int successCode = 200;
int failureCode = 404;
int maxAge = 0;
std::string mimeType = "";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"" is the default value for std::string anyway.

std::string_view filePath = tc->makePath(txn, output);

ifstr.open(tc->filePath);
VDEBUG("Requested file path: %s", filePath.data());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You may spend centuries in Purgatory for assuming an std::string_view is null terminated. Especially when you could just have makePath() return std::string const &.

Copy link
Contributor

@ywkaras ywkaras left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please never tell Bjarne Stroustrup I approved this.

@zwoop zwoop merged commit e37b35d into apache:master Nov 17, 2022
@zwoop zwoop deleted the StaticHitDirs branch November 17, 2022 15:25
zwoop added a commit that referenced this pull request Nov 17, 2022
* Adds support for serving static files out of a directory

* Change makePath to take a output container, and return string_view instead

* Fixes per AMC's review

* Make all clang compilers happy, maybe

(cherry picked from commit e37b35d)
@zwoop
Copy link
Contributor Author

zwoop commented Nov 17, 2022

Cherry-picked to v9.2.x

@zwoop zwoop modified the milestones: 10.0.0, 9.2.0 Nov 17, 2022
masaori335 pushed a commit to masaori335/trafficserver that referenced this pull request Feb 21, 2023
…#9107)

* Adds support for serving static files out of a directory

* Change makePath to take a output container, and return string_view instead

* Fixes per AMC's review

* Make all clang compilers happy, maybe

(cherry picked from commit e37b35d)
masaori335 pushed a commit to masaori335/trafficserver that referenced this pull request Feb 21, 2023
* asf/9.2.x:
  Revert "Make separate read and write vc_handlers (apache#8301)"
  AuTest: Update to Proxy Verifier 2.5.2 (apache#9223)
  AuTest: Update to Proxy Verifier v2.5.0 (apache#9221)
  Updated ChangeLog
  Adding back set_connect_fail for generic I/O error (apache#9181)
  AuTest: make MakeATSProcess accessible for TestRuns (apache#9195)
  Traffic Dump: Allow unlimited disk utilization (apache#9186)
  AuTest: bind stdout/stderr to traffic.out (apache#8919)
  Adds support for serving statichit content out of a directory (apache#9107)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants