Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@i110
Copy link
Contributor

@i110 i110 commented Sep 6, 2017

Related to #1371, this PR allows h2o to assign custom handler to the files with no extension.

As an example:

file.custom-handler:
  extension: default
  fastcgi.spawn: "exec /path/to/share/h2o/fastcgi-cgi"
hosts:
  default:
    paths:
      /robots.txt:
        file.file: /path/to/doc_root/noextcgi

Copy link
Member

@kazuho kazuho left a comment

Choose a reason for hiding this comment

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

Thank you for the PR. It looks mostly fine.

I have left in-line comments. Please let me know what you think.

if (strcmp(node->data.scalar, "default") == 0) {
return node->data.scalar;
} else if (assert_is_extension(cmd, node) == 0) {
return node->data.scalar + 1;
Copy link
Member

Choose a reason for hiding this comment

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

The function seems to either return "default" or return the extension stripping the preceding dot.

Does the fact mean that we can no longer register .default as an extension?

t/50file-file.t Outdated
my ($proto, $port, $cmd) = @_;
my $resp = `$cmd --silent $proto://127.0.0.1:$port/robots.txt?name=Tobor`;
is $resp, "Hello Tobor";
});
Copy link
Member

Choose a reason for hiding this comment

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

The test tests if the custom handler works well with file.file.

Could we also have a test case that maps all files under a directory to CGI? To rephrase, I would appreciate it if we could have a test case covering the use-case of SetHandler cgi-script in Apache.

<Directory "/home/*/public_html/cgi-bin">
    Options ExecCGI
    SetHandler cgi-script
</Directory>

h2o_configurator_errprintf(cmd, node, "given extension \"%s\" does not start with a \".\"", node->data.scalar);
return -1;
}
if (strlen(node->data.scalar) == 1) {
Copy link
Member

Choose a reason for hiding this comment

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

This is definitely a nitpick, but how about changing to node->data.scalar[1] == '\0'?

return 0;
}

static const char *get_ext(h2o_configurator_command_t *cmd, yoml_t *node)
Copy link
Member

Choose a reason for hiding this comment

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

How about changing the name of the function to normalize_ext or something?

my $server = spawn_h2o(<< "EOT");
file.custom-handler:
extension: ["default", ".cgi"]
fastcgi.spawn: "exec \$H2O_ROOT/share/h2o/fastcgi-cgi"
Copy link
Member

Choose a reason for hiding this comment

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

Could we use possibly do file.mime.settypes: {} as well to reset the existing mime-type here, and see that a file with .html extension gets treated as a CGI?

@i110 i110 force-pushed the i110/dynamic-default-mime-type branch from e6b4076 to e84b551 Compare September 6, 2017 08:55
@i110 i110 force-pushed the i110/dynamic-default-mime-type branch from 3653f6f to b0b7701 Compare September 7, 2017 07:40
@kazuho kazuho merged commit 8b6e460 into master Sep 12, 2017
@kazuho
Copy link
Member

kazuho commented Sep 12, 2017

Thank you for the changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants