mirror of
https://github.com/abapGit/abapGit.git
synced 2025-05-01 12:20:51 +08:00
add smart response checks for ref discovery (#1942)
* add smart response checks for ref discovery Added content-type check and content regex check for reference discovery see https://github.com/schacon/igithub/blob/master/http-protocol.txt * move ref check constants to TRANSPORT class the check constants - content regex and responce Content-Type - don't have to be global right now so moved from zif_abapgit_definitionsto zcl_abapgit_git_transport * PP and activate
This commit is contained in:
parent
d21bbb6caa
commit
ab1fce00fe
|
@ -33,6 +33,12 @@ CLASS zcl_abapgit_git_transport DEFINITION
|
|||
receive TYPE string VALUE 'receive', "#EC NOTEXT
|
||||
upload TYPE string VALUE 'upload', "#EC NOTEXT
|
||||
END OF c_service.
|
||||
CONSTANTS: BEGIN OF c_smart_response_check,
|
||||
BEGIN OF get_refs,
|
||||
content_regex TYPE string VALUE '^[0-9a-f]{4}#',
|
||||
content_type TYPE string VALUE 'application/x-git-<service>-pack-advertisement',
|
||||
END OF get_refs,
|
||||
END OF c_smart_response_check.
|
||||
|
||||
CLASS-METHODS branch_list
|
||||
IMPORTING iv_url TYPE string
|
||||
|
@ -83,12 +89,19 @@ CLASS zcl_abapgit_git_transport IMPLEMENTATION.
|
|||
METHOD branch_list.
|
||||
|
||||
DATA: lv_data TYPE string.
|
||||
|
||||
DATA: lv_expected_content_type TYPE string.
|
||||
|
||||
eo_client = zcl_abapgit_http=>create_by_url(
|
||||
iv_url = iv_url
|
||||
iv_service = iv_service ).
|
||||
|
||||
lv_expected_content_type = c_smart_response_check-get_refs-content_type.
|
||||
REPLACE '<service>' IN lv_expected_content_type WITH iv_service.
|
||||
|
||||
eo_client->check_smart_response(
|
||||
iv_expected_content_type = lv_expected_content_type
|
||||
iv_content_regex = c_smart_response_check-get_refs-content_regex ).
|
||||
|
||||
lv_data = eo_client->get_cdata( ).
|
||||
|
||||
CREATE OBJECT eo_branch_list
|
||||
|
@ -186,7 +199,7 @@ CLASS zcl_abapgit_git_transport IMPLEMENTATION.
|
|||
zcl_abapgit_git_utils=>get_null( ) &&
|
||||
` ` &&
|
||||
lv_cap_list &&
|
||||
zif_abapgit_definitions=>c_newline. "#EC NOTEXT
|
||||
zif_abapgit_definitions=>c_newline. "#EC NOTEXT
|
||||
lv_cmd_pkt = zcl_abapgit_git_utils=>pkt_string( lv_line ).
|
||||
|
||||
lv_buffer = lv_cmd_pkt && '0000'.
|
||||
|
@ -260,14 +273,14 @@ CLASS zcl_abapgit_git_transport IMPLEMENTATION.
|
|||
&& ` ` && lv_capa && zif_abapgit_definitions=>c_newline. "#EC NOTEXT
|
||||
ELSE.
|
||||
lv_line = 'want' && ` ` && <ls_branch>-sha1
|
||||
&& zif_abapgit_definitions=>c_newline. "#EC NOTEXT
|
||||
&& zif_abapgit_definitions=>c_newline. "#EC NOTEXT
|
||||
ENDIF.
|
||||
lv_buffer = lv_buffer && zcl_abapgit_git_utils=>pkt_string( lv_line ).
|
||||
ENDLOOP.
|
||||
|
||||
IF iv_deepen = abap_true.
|
||||
lv_buffer = lv_buffer && zcl_abapgit_git_utils=>pkt_string( 'deepen 1'
|
||||
&& zif_abapgit_definitions=>c_newline ). "#EC NOTEXT
|
||||
&& zif_abapgit_definitions=>c_newline ). "#EC NOTEXT
|
||||
ENDIF.
|
||||
|
||||
lv_buffer = lv_buffer
|
||||
|
|
|
@ -9,15 +9,17 @@ CLASS zcl_abapgit_http_client DEFINITION PUBLIC CREATE PUBLIC.
|
|||
set_digest
|
||||
IMPORTING io_digest TYPE REF TO zcl_abapgit_http_digest,
|
||||
send_receive_close
|
||||
IMPORTING
|
||||
iv_data TYPE xstring
|
||||
RETURNING
|
||||
VALUE(rv_data) TYPE xstring
|
||||
IMPORTING iv_data TYPE xstring
|
||||
RETURNING VALUE(rv_data) TYPE xstring
|
||||
RAISING zcx_abapgit_exception,
|
||||
get_cdata
|
||||
RETURNING VALUE(rv_value) TYPE string,
|
||||
check_http_200
|
||||
RAISING zcx_abapgit_exception,
|
||||
check_smart_response
|
||||
IMPORTING iv_expected_content_type TYPE string
|
||||
iv_content_regex TYPE string
|
||||
RAISING zcx_abapgit_exception,
|
||||
send_receive
|
||||
RAISING zcx_abapgit_exception,
|
||||
set_headers
|
||||
|
@ -33,7 +35,7 @@ ENDCLASS.
|
|||
|
||||
|
||||
|
||||
CLASS ZCL_ABAPGIT_HTTP_CLIENT IMPLEMENTATION.
|
||||
CLASS zcl_abapgit_http_client IMPLEMENTATION.
|
||||
|
||||
|
||||
METHOD check_http_200.
|
||||
|
@ -41,7 +43,6 @@ CLASS ZCL_ABAPGIT_HTTP_CLIENT IMPLEMENTATION.
|
|||
DATA: lv_code TYPE i,
|
||||
lv_text TYPE string.
|
||||
|
||||
|
||||
mi_client->response->get_status(
|
||||
IMPORTING
|
||||
code = lv_code ).
|
||||
|
@ -66,6 +67,29 @@ CLASS ZCL_ABAPGIT_HTTP_CLIENT IMPLEMENTATION.
|
|||
ENDMETHOD. "http_200
|
||||
|
||||
|
||||
METHOD check_smart_response.
|
||||
|
||||
DATA: lv_content_type TYPE string.
|
||||
DATA: lv_data TYPE string.
|
||||
|
||||
IF iv_expected_content_type IS NOT INITIAL.
|
||||
lv_content_type = mi_client->response->get_content_type( ).
|
||||
IF lv_content_type <> iv_expected_content_type.
|
||||
zcx_abapgit_exception=>raise( 'Wrong Content-Type sent by server - no fallback to the dumb protocol!' ).
|
||||
ENDIF.
|
||||
ENDIF.
|
||||
|
||||
IF iv_content_regex IS NOT INITIAL.
|
||||
lv_data = mi_client->response->get_cdata( ).
|
||||
FIND REGEX iv_content_regex IN lv_data.
|
||||
IF sy-subrc <> 0.
|
||||
zcx_abapgit_exception=>raise( 'Wrong Content sent by server' ).
|
||||
ENDIF.
|
||||
ENDIF.
|
||||
|
||||
ENDMETHOD.
|
||||
|
||||
|
||||
METHOD close.
|
||||
mi_client->close( ).
|
||||
ENDMETHOD.
|
||||
|
|
|
@ -21,7 +21,7 @@ INTERFACE zif_abapgit_definitions PUBLIC.
|
|||
ty_file_signature WITH UNIQUE KEY path filename .
|
||||
TYPES:
|
||||
BEGIN OF ty_file.
|
||||
INCLUDE TYPE ty_file_signature.
|
||||
INCLUDE TYPE ty_file_signature.
|
||||
TYPES: data TYPE xstring,
|
||||
END OF ty_file .
|
||||
TYPES:
|
||||
|
@ -107,7 +107,7 @@ INTERFACE zif_abapgit_definitions PUBLIC.
|
|||
TYPES: ty_yes_no TYPE c LENGTH 1.
|
||||
|
||||
TYPES: BEGIN OF ty_overwrite.
|
||||
INCLUDE TYPE ty_item.
|
||||
INCLUDE TYPE ty_item.
|
||||
TYPES: decision TYPE ty_yes_no,
|
||||
END OF ty_overwrite.
|
||||
|
||||
|
@ -216,7 +216,7 @@ INTERFACE zif_abapgit_definitions PUBLIC.
|
|||
ty_seocompotx_tt TYPE STANDARD TABLE OF seocompotx WITH DEFAULT KEY .
|
||||
TYPES:
|
||||
BEGIN OF ty_tpool.
|
||||
INCLUDE TYPE textpool.
|
||||
INCLUDE TYPE textpool.
|
||||
TYPES: split TYPE c LENGTH 8.
|
||||
TYPES: END OF ty_tpool .
|
||||
TYPES:
|
||||
|
|
Loading…
Reference in New Issue
Block a user