|
3 | 3 | */ |
4 | 4 | component implements="HyperHttpClientInterface" { |
5 | 5 |
|
6 | | - /** |
7 | | - * Execute the HyperRequest and map it to a HyperResponse. |
8 | | - * |
9 | | - * @req The HyperRequest to execute. |
10 | | - * |
11 | | - * @returns A HyperResponse of the executed request. |
12 | | - */ |
13 | | - public HyperResponse function send( required HyperRequest req ) { |
14 | | - var cfhttpResponse = makeCFHTTPRequest( req ); |
15 | | - return new Hyper.models.HyperResponse( |
16 | | - originalRequest = req, |
17 | | - charset = cfhttpResponse.charset ?: "UTF-8", |
18 | | - statusCode = cfhttpResponse.responseheader.status_code ?: 504, |
19 | | - headers = normalizeHeaders( cfhttpResponse ), |
20 | | - data = cfhttpResponse.filecontent |
21 | | - ); |
22 | | - } |
| 6 | + /** |
| 7 | + * Execute the HyperRequest and map it to a HyperResponse. |
| 8 | + * |
| 9 | + * @req The HyperRequest to execute. |
| 10 | + * |
| 11 | + * @returns A HyperResponse of the executed request. |
| 12 | + */ |
| 13 | + public HyperResponse function send( required HyperRequest req ) { |
| 14 | + var cfhttpResponse = makeCFHTTPRequest( req ); |
| 15 | + return new Hyper.models.HyperResponse( |
| 16 | + originalRequest = req, |
| 17 | + charset = cfhttpResponse.charset ?: "UTF-8", |
| 18 | + statusCode = cfhttpResponse.responseheader.status_code ?: 504, |
| 19 | + headers = normalizeHeaders( cfhttpResponse ), |
| 20 | + data = cfhttpResponse.filecontent |
| 21 | + ); |
| 22 | + } |
23 | 23 |
|
24 | | - /** |
25 | | - * Makes an HTTP request using CFHTTP. |
26 | | - * |
27 | | - * @req The request to execute |
28 | | - * |
29 | | - * @returns The CFHTTP response struct. |
30 | | - */ |
31 | | - private struct function makeCFHTTPRequest( required HyperRequest req ) { |
32 | | - local.res = ""; |
33 | | - var attrCollection = { |
34 | | - result = "local.res", |
35 | | - timeout = req.getTimeout(), |
36 | | - url = req.getFullUrl(), |
37 | | - method = req.getMethod(), |
38 | | - redirect = false, |
39 | | - throwonerror = req.getThrowOnError(), |
40 | | - resolveURL = req.getResolveUrls() |
41 | | - }; |
| 24 | + /** |
| 25 | + * Makes an HTTP request using CFHTTP. |
| 26 | + * |
| 27 | + * @req The request to execute |
| 28 | + * |
| 29 | + * @returns The CFHTTP response struct. |
| 30 | + */ |
| 31 | + private struct function makeCFHTTPRequest( required HyperRequest req ) { |
| 32 | + local.res = ""; |
| 33 | + var attrCollection = { |
| 34 | + result : "local.res", |
| 35 | + timeout : req.getTimeout(), |
| 36 | + url : req.getFullUrl(), |
| 37 | + method : req.getMethod(), |
| 38 | + redirect : false, |
| 39 | + throwonerror : req.getThrowOnError(), |
| 40 | + resolveURL : req.getResolveUrls() |
| 41 | + }; |
42 | 42 |
|
43 | | - if ( len( req.getUsername() ) ) { |
44 | | - attrCollection[ "username" ] = req.getUsername(); |
45 | | - } |
46 | | - if ( len( req.getPassword() ) ) { |
47 | | - attrCollection[ "password" ] = req.getPassword(); |
48 | | - } |
| 43 | + if ( len( req.getUsername() ) ) { |
| 44 | + attrCollection[ "username" ] = req.getUsername(); |
| 45 | + } |
| 46 | + if ( len( req.getPassword() ) ) { |
| 47 | + attrCollection[ "password" ] = req.getPassword(); |
| 48 | + } |
49 | 49 |
|
50 | | - cfhttp( attributeCollection = attrCollection ) { |
51 | | - var headers = req.getHeaders(); |
52 | | - for ( var name in headers ) { |
53 | | - cfhttpparam( |
54 | | - type = "header", |
55 | | - name = name, |
56 | | - value = headers[ name ] |
57 | | - ); |
58 | | - } |
| 50 | + cfhttp( attributeCollection=attrCollection ) { |
| 51 | + var headers = req.getHeaders(); |
| 52 | + for ( var name in headers ) { |
| 53 | + cfhttpparam( |
| 54 | + type ="header", |
| 55 | + name =name, |
| 56 | + value=headers[ name ] |
| 57 | + ); |
| 58 | + } |
59 | 59 |
|
60 | | - var queryParams = req.getQueryParams(); |
61 | | - for ( var name in queryParams ) { |
62 | | - cfhttpparam( |
63 | | - type = "url", |
64 | | - name = name, |
65 | | - value = queryParams[ name ] |
66 | | - ); |
67 | | - } |
| 60 | + var queryParams = req.getQueryParams(); |
| 61 | + for ( var name in queryParams ) { |
| 62 | + cfhttpparam( |
| 63 | + type ="url", |
| 64 | + name =name, |
| 65 | + value=queryParams[ name ] |
| 66 | + ); |
| 67 | + } |
68 | 68 |
|
69 | | - if ( req.hasBody() ) { |
70 | | - if ( req.getBodyFormat() == "json" ) { |
71 | | - cfhttpparam( type = "body", value = req.prepareBody() ); |
72 | | - } |
73 | | - else if ( req.getBodyFormat() == "formFields" ) { |
74 | | - var body = req.getBody(); |
75 | | - for ( var fieldName in body ) { |
76 | | - cfhttpparam( |
77 | | - type = "formfield", |
78 | | - name = fieldName, |
79 | | - value = body[ fieldName ] |
80 | | - ); |
81 | | - } |
82 | | - } |
83 | | - else { |
84 | | - cfhttpparam( type = "body", value = req.prepareBody() ); |
85 | | - } |
86 | | - } |
87 | | - } |
88 | | - return local.res; |
89 | | - } |
| 69 | + if ( req.hasBody() ) { |
| 70 | + if ( req.getBodyFormat() == "json" ) { |
| 71 | + cfhttpparam( type="body", value=req.prepareBody() ); |
| 72 | + } else if ( req.getBodyFormat() == "formFields" ) { |
| 73 | + var body = req.getBody(); |
| 74 | + for ( var fieldName in body ) { |
| 75 | + cfhttpparam( |
| 76 | + type ="formfield", |
| 77 | + name =fieldName, |
| 78 | + value=body[ fieldName ] |
| 79 | + ); |
| 80 | + } |
| 81 | + } else { |
| 82 | + cfhttpparam( type="body", value=req.prepareBody() ); |
| 83 | + } |
| 84 | + } |
| 85 | + } |
| 86 | + return local.res; |
| 87 | + } |
90 | 88 |
|
91 | | - /** |
92 | | - * Normalizes the headers from a CFHTTP response into a normalized struct. |
93 | | - * |
94 | | - * @cfhttpResponse The cfhttp response struct. |
95 | | - * |
96 | | - * @returns A struct of normalized headers. |
97 | | - */ |
98 | | - private struct function normalizeHeaders( required struct cfhttpResponse ) { |
99 | | - var headers = {}; |
100 | | - cfhttpResponse.responseheader.each( function( name, value ) { |
101 | | - headers[ lcase( name ) ] = value; |
102 | | - } ); |
103 | | - return headers; |
104 | | - } |
| 89 | + /** |
| 90 | + * Normalizes the headers from a CFHTTP response into a normalized struct. |
| 91 | + * |
| 92 | + * @cfhttpResponse The cfhttp response struct. |
| 93 | + * |
| 94 | + * @returns A struct of normalized headers. |
| 95 | + */ |
| 96 | + private struct function normalizeHeaders( required struct cfhttpResponse ) { |
| 97 | + var headers = {}; |
| 98 | + cfhttpResponse.responseheader.each( function( name, value ) { |
| 99 | + headers[ lCase( name ) ] = value; |
| 100 | + } ); |
| 101 | + return headers; |
| 102 | + } |
105 | 103 |
|
106 | 104 | } |
0 commit comments