-
Notifications
You must be signed in to change notification settings - Fork 474
/
HeaderPreprocessor.java
88 lines (76 loc) · 3.34 KB
/
HeaderPreprocessor.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.hadoop.ozone.s3;
import javax.annotation.Priority;
import javax.ws.rs.container.ContainerRequestContext;
import javax.ws.rs.container.ContainerRequestFilter;
import javax.ws.rs.container.PreMatching;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.MultivaluedMap;
import javax.ws.rs.ext.Provider;
import java.io.IOException;
/**
* Filter to adjust request headers for compatible reasons.
*
* It should be executed AFTER signature check (VirtualHostStyleFilter) as the
* original Content-Type could be part of the base of the signature.
*/
@Provider
@PreMatching
@Priority(HeaderPreprocessor.PRIORITY)
public class HeaderPreprocessor implements ContainerRequestFilter {
public static final int PRIORITY = VirtualHostStyleFilter.PRIORITY +
S3GatewayHttpServer.FILTER_PRIORITY_DO_AFTER;
public static final String MULTIPART_UPLOAD_MARKER = "ozone/mpu";
public static final String CONTENT_TYPE = "Content-Type";
public static final String ORIGINAL_CONTENT_TYPE =
"X-Ozone-Original-Content-Type";
@Override
public void filter(ContainerRequestContext requestContext) throws
IOException {
MultivaluedMap<String, String> queryParameters =
requestContext.getUriInfo().getQueryParameters();
if (requestContext.getHeaderString(CONTENT_TYPE) != null) {
requestContext.getHeaders().putSingle(ORIGINAL_CONTENT_TYPE,
requestContext.getHeaderString(CONTENT_TYPE));
}
if (queryParameters.containsKey("delete")) {
//aws cli doesn't send proper Content-Type and by default POST requests
//processed as form-url-encoded. Here we can fix this.
requestContext.getHeaders()
.putSingle(CONTENT_TYPE, MediaType.APPLICATION_XML);
}
if (queryParameters.containsKey("uploadId")) {
//aws cli doesn't send proper Content-Type and by default POST requests
//processed as form-url-encoded. Here we can fix this.
requestContext.getHeaders()
.putSingle(CONTENT_TYPE, MediaType.APPLICATION_XML);
} else if (queryParameters.containsKey("uploads")) {
// uploads defined but uploadId is not --> this is the creation of the
// multi-part-upload requests.
//
//In AWS SDK for go uses application/octet-stream which also
//should be fixed to route the request to the right jaxrs method.
//
//Should be empty instead of XML as the body is empty which can not be
//serialized as as CompleteMultipartUploadRequest
requestContext.getHeaders()
.putSingle(CONTENT_TYPE, MULTIPART_UPLOAD_MARKER);
}
}
}