JoaoJandre commented on code in PR #7445:
URL: https://github.com/apache/cloudstack/pull/7445#discussion_r1171753491
##########
services/secondary-storage/server/src/main/java/org/apache/cloudstack/storage/resource/HttpUploadServerHandler.java:
##########
@@ -130,22 +130,16 @@ public void channelRead0(ChannelHandlerContext ctx,
HttpObject msg) throws Excep
long contentLength = 0;
for (Entry<String, String> entry : request.headers()) {
- switch (entry.getKey()) {
- case HEADER_SIGNATURE:
- signature = entry.getValue();
- break;
- case HEADER_METADATA:
- metadata = entry.getValue();
- break;
- case HEADER_EXPIRES:
- expires = entry.getValue();
- break;
- case HEADER_HOST:
- hostname = entry.getValue();
- break;
- case HttpHeaders.Names.CONTENT_LENGTH:
- contentLength = Long.parseLong(entry.getValue());
- break;
+ if (HEADER_SIGNATURE.equalsIgnoreCase(entry.getKey())) {
+ signature = entry.getValue();
+ } else if
(HEADER_METADATA.equalsIgnoreCase(entry.getKey())) {
+ metadata = entry.getValue();
+ } else if
(HEADER_EXPIRES.equalsIgnoreCase(entry.getKey())) {
+ expires = entry.getValue();
+ } else if (HEADER_HOST.equalsIgnoreCase(entry.getKey())) {
+ hostname = entry.getValue();
+ } else if
(HttpHeaders.Names.CONTENT_LENGTH.equalsIgnoreCase(entry.getKey())) {
+ contentLength = Long.parseLong(entry.getValue());
Review Comment:
```suggestion
switch (entry.getKey().toLowerCase()) {
case HEADER_SIGNATURE:
signature = entry.getValue();
break;
case HEADER_METADATA:
metadata = entry.getValue();
break;
case HEADER_EXPIRES:
expires = entry.getValue();
break;
case HEADER_HOST:
hostname = entry.getValue();
break;
case CONTENT_LENGTH:
contentLength = Long.parseLong(entry.getValue());
break;
```
I think we should leave the switch case, which is more efficient and
readable, and simply use `toLowerCase()` on the entry. Apart from this
suggestion, you would have to define the `CONTENT_LENGTH` static variable
(which should be on lowercase), as it is done with the rest of the headers in
this class.
Lastly, down on the `writeResponse` method, the line
`response.headers().set(CONTENT_LENGTH, buf.readableBytes());` would have to be
changed to `response.headers().set(HttpHeaders.Names.CONTENT_LENGTH,
buf.readableBytes());` in order to maintain current behavior.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]