-
Notifications
You must be signed in to change notification settings - Fork 26.5k
Support more content types for Triple protocol #13387
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
Changes from 53 commits
e02eea3
0832152
b42edad
5edf4c7
f3f803d
59dc920
a743c4b
75407cf
af4c32d
501b7bd
e03ba37
8397c11
5a620fd
9578ee9
e13fb8d
e9a6bee
03ed56e
feaaccf
7048fb8
2f0e6fd
e4c7af0
f73cb06
39da7a8
db52310
383cc56
1709ab0
f2333f3
d3f4b35
18794c2
4e9ac86
ae39e25
17141ea
866735c
2623f89
9c72769
a5d5f59
659a209
3631d19
3123eb9
0ec254b
16945fd
0dea4ff
5e5b436
d4fb966
67c5e37
a46f15f
98af134
5da0b46
7e574dd
0589b4c
5f28786
d07c60a
d58b37e
98340f7
0fe32fc
534f0a8
a38e9fa
ebf3021
9f2a120
8a1a737
38d0c49
380ae6e
ec0d268
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why add this class? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's currently used for determine if a |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/* | ||
* 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 | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* 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.dubbo.remoting.http12.message; | ||
|
||
public interface CodecSupportStrategy { | ||
|
||
boolean supportDecode(String mediaType); | ||
|
||
boolean supportEncode(String mediaType); | ||
|
||
MediaType contentType(); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/* | ||
* 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 | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* 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.dubbo.remoting.http12.message.codec; | ||
|
||
import org.apache.dubbo.common.URL; | ||
import org.apache.dubbo.remoting.http12.HttpHeaders; | ||
import org.apache.dubbo.remoting.http12.message.HttpMessageCodec; | ||
import org.apache.dubbo.remoting.http12.message.HttpMessageCodecFactory; | ||
import org.apache.dubbo.rpc.model.FrameworkModel; | ||
|
||
import java.io.ByteArrayOutputStream; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
|
||
public class CodecUtils { | ||
|
||
public static HttpMessageCodec determineHttpMessageCodec( | ||
FrameworkModel frameworkModel, HttpHeaders headers, URL url, boolean decode) { | ||
String mediaType = headers.getContentType(); | ||
// encode | ||
if (!decode && headers.getAccept() != null) { | ||
mediaType = headers.getAccept(); | ||
} | ||
HttpMessageCodecFactory factory = determineHttpMessageCodecFactory(frameworkModel, mediaType, decode); | ||
if (factory != null) { | ||
return factory.createCodec(url, frameworkModel, mediaType); | ||
} | ||
return null; | ||
} | ||
|
||
public static HttpMessageCodecFactory determineHttpMessageCodecFactory( | ||
FrameworkModel frameworkModel, String mediaType, boolean decode) { | ||
frameworkModel.getExtensionLoader(HttpMessageCodecFactory.class).getSupportedExtensions(); | ||
for (HttpMessageCodecFactory httpMessageCodecFactory : | ||
frameworkModel.getExtensionLoader(HttpMessageCodecFactory.class).getActivateExtensions()) { | ||
if (decode) { | ||
if (httpMessageCodecFactory.codecSupport().supportDecode(mediaType)) { | ||
return httpMessageCodecFactory; | ||
} | ||
} else { | ||
// encode | ||
if (httpMessageCodecFactory.codecSupport().supportEncode(mediaType)) { | ||
return httpMessageCodecFactory; | ||
} | ||
} | ||
} | ||
return null; | ||
} | ||
|
||
public static ByteArrayOutputStream toByteArrayStream(InputStream in) throws IOException { | ||
ByteArrayOutputStream result = new ByteArrayOutputStream(); | ||
byte[] buffer = new byte[1024]; | ||
int length; | ||
while ((length = in.read(buffer)) != -1) { | ||
result.write(buffer, 0, length); | ||
} | ||
return result; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* | ||
* 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 | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* 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.dubbo.remoting.http12.message.codec; | ||
|
||
import org.apache.dubbo.remoting.http12.message.CodecSupportStrategy; | ||
import org.apache.dubbo.remoting.http12.message.MediaType; | ||
|
||
public class DefaultSupportStrategy implements CodecSupportStrategy { | ||
private final MediaType mediaType; | ||
|
||
public DefaultSupportStrategy(MediaType mediaType) { | ||
this.mediaType = mediaType; | ||
} | ||
|
||
public boolean supportDecode(String mediaType) { | ||
return mediaType != null && mediaType.startsWith(this.mediaType.getName()); | ||
} | ||
|
||
public boolean supportEncode(String mediaType) { | ||
return mediaType != null && (mediaType.contains(this.mediaType.getName())); | ||
} | ||
|
||
@Override | ||
public MediaType contentType() { | ||
return mediaType; | ||
} | ||
} |
Uh oh!
There was an error while loading. Please reload this page.