994cd7d7e7dafc4c5dacb269793b2b04df608573
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI / src / internal / WebView / WebHttpRequestInterceptor.cs
1 /*
2  * Copyright (c) 2021 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17
18 using System;
19 using System.ComponentModel;
20
21 namespace Tizen.NUI
22 {
23     /// <summary>
24     /// It is a class for http request interceptor of web view.
25     /// </summary>
26     [EditorBrowsable(EditorBrowsableState.Never)]
27     public class WebHttpRequestInterceptor : Disposable
28     {
29         internal WebHttpRequestInterceptor(global::System.IntPtr cPtr, bool cMemoryOwn) : base(cPtr, cMemoryOwn)
30         {
31         }
32
33         /// This will not be public opened.
34         /// <param name="swigCPtr"></param>
35         [EditorBrowsable(EditorBrowsableState.Never)]
36         protected override void ReleaseSwigCPtr(System.Runtime.InteropServices.HandleRef swigCPtr)
37         {
38             Interop.WebHttpRequestInterceptor.DeleteWebHttpRequestInterceptor(swigCPtr);
39         }
40
41         /// <summary>
42         /// Gets url of intercepted request.
43         /// </summary>
44         [EditorBrowsable(EditorBrowsableState.Never)]
45         public string Url
46         {
47             get
48             {
49                 return Interop.WebHttpRequestInterceptor.GetUrl(SwigCPtr);
50             }
51         }
52
53         /// <summary>
54         /// Ignores this request.
55         /// </summary>
56         [EditorBrowsable(EditorBrowsableState.Never)]
57         public bool Ignore()
58         {
59             bool result = Interop.WebHttpRequestInterceptor.Ignore(SwigCPtr);
60             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
61             return result;
62         }
63
64         /// <summary>
65         /// Sets status code and status text of response for intercepted request.
66         /// <param name="statusCode">Status code of response</param>
67         /// <param name="customStatusText">Status text of response</param>
68         /// </summary>
69         [EditorBrowsable(EditorBrowsableState.Never)]
70         public bool SetResponseStatus(int statusCode, string customStatusText)
71         {
72             bool result = Interop.WebHttpRequestInterceptor.SetResponseStatus(SwigCPtr, statusCode, customStatusText);
73             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
74             return result;
75         }
76
77         /// <summary>
78         /// Adds HTTP header to response for intercepted request.
79         /// <param name="fieldName">Key of response header</param>
80         /// <param name="fieldValue">Value of response header</param>
81         /// </summary>
82         [EditorBrowsable(EditorBrowsableState.Never)]
83         public bool AddResponseHeader(string fieldName, string fieldValue)
84         {
85             bool result = Interop.WebHttpRequestInterceptor.AddResponseHeader(SwigCPtr, fieldName, fieldValue);
86             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
87             return result;
88         }
89
90         /// <summary>
91         /// Writes whole response body at once.
92         /// <param name="body">Contents of response</param>
93         /// <param name="length">Length of Contents of response</param>
94         /// </summary>
95         [EditorBrowsable(EditorBrowsableState.Never)]
96         public bool AddResponseBody(string body, uint length)
97         {
98             bool result = Interop.WebHttpRequestInterceptor.AddResponseBody(SwigCPtr, body, length);
99             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
100             return result;
101         }
102     }
103 }