-
Notifications
You must be signed in to change notification settings - Fork 141
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
Implement PEP 691 JSON Simple Index Support #1138
Comments
My suggestions here: Write out 3 files
For Apache, if you have Options -Indexes +Multiviews
DirectoryIndex index
AddType application/vnd.pypi.simple.v1+json v1_json
AddType application/vnd.pypi.simple.v1+html v1_html This will:
You can use this in a Docker container using the FROM httpd
RUN echo '\n\
LoadModule negotiation_module modules/mod_negotiation.so\n\
\n\
<Directory "/usr/local/apache2/htdocs">\n\
AllowOverride All\n\
</Directory>' >> /usr/local/apache2/conf/httpd.conf This can be ran using Alternatively, you can use nginx. The adapted banderx config looks something like this: daemon off;
user nginx;
worker_processes auto;
error_log /dev/stderr info;
pid /run/nginx.pid;
events {
worker_connections 2048;
}
http {
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /dev/stdout main;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 69;
types_hash_max_size 2048;
include /etc/nginx/mime.types;
default_type application/octet-stream;
map $http_accept $mirror_suffix {
default ".html";
"~*application/vnd\.pypi\.simple\.latest\+json" ".v1_json";
"~*application/vnd\.pypi\.simple\.latest\+html" ".v1_html";
"~*application/vnd\.pypi\.simple\.v1\+json" ".v1_json";
"~*application/vnd\.pypi\.simple\.v1\+html" ".v1_html";
"~*text/html" ".html";
}
map $arg_format $mirror_suffix_via_url {
"application/vnd.pypi.simple.latest+json" ".v1_json";
"application/vnd.pypi.simple.latest+html" ".v1_html";
"application/vnd.pypi.simple.v1+json" ".v1_json";
"application/vnd.pypi.simple.v1+html" ".v1_html";
"text/html" ".html";
}
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name banderx;
root /data/pypi/web;
autoindex on;
charset utf-8;
location /simple/ {
# Uncomment to support hash_index = true bandersnatch mirrors
# rewrite ^/simple/([^/])([^/]*)/$ /simple/$1/$1$2/ last;
# rewrite ^/simple/([^/])([^/]*)/([^/]+)$/ /simple/$1/$1$2/$3 last;
index index$mirror_suffix_via_url index$mirror_suffix;
types {
application/vnd.pypi.simple.v1+json v1_json;
application/vnd.pypi.simple.v1+html v1_html;
text/html html;
}
# Uncomment to support conneg for files other than
# index, so that /simple/foo will map to /simple/foo.html,
# /simple/foo.v1_html, or /simple/foo.v1_json based on the
# Accept header.
# try_files $uri$mirror_suffix $uri $uri/ =404;
}
# Let us set the correct mime type for all the JSON
location /json/ {
default_type application/json;
}
location /pypi/ {
default_type application/json;
}
error_page 404 /404.html;
location = /40x.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}
} The big differences between Apache and Nginx here are:
Personally, I would recommend sticking with nginx for I don't think the fact the Nginx's conneg support is not really actually implemented as conneg, but instead some basic regex matching will actually matter for anyone unless they're purposely trying to do weird things, but I think the ability to specifically pick which version is the default is a really nice thing as it lets a mirror operator decide what level of compatibility they want (my above config chooses max compatability) and I think that the extra features supported by the nginx config ( On the other hand, I think that Apache's behavior of defaulting to whatever response is smallest is nice for saving bandwidth, but I think it's kind of weird that different URLs under |
One additional thing: The above assumes that bandersnatch is going to swap out from writing just Some people may want to not rely on conneg, and have different URLs for different content types. I think bandersnatch could support this pretty easily using two options:
|
Add logic for bandersnatch to save both the HTML and JSON simple index files. This will allow people to serve both the HTML and JSON in their mirrors.
We should also update docs + give an example way to serve based on request headers (conneg) as outlined in PEP691.
The text was updated successfully, but these errors were encountered: